View Full Version : Using OpenCV with OpenGL for texture mapping
05-18-2012, 06:01 AM
I would like to use opencv with openGL for texture mapping. With the use of opencv, channel RGB values can be manipulated. Now, suppose, my texture XY coorodinate range is(-4, -4) to (4, 4). My image has been texture mapped to the window with dimension (500, 500). For mapping between coordinate and pixel, I have used the following relationship:
x,y (0,0) to (8,8) mapping to pixel for 0,0 to (500, 500);
now for a particular (x,y)
x += 4 ;
if ( y >= 0)
y = 4 - y;
y = 4-(-y);
corresponding pixel value (x*500/8) and (y*500/8);
Is this mapping ok between x,y coordinate and pixel or any better method is available?
05-23-2012, 02:34 AM
Hi,I need the reply to my query a bit urgently. Please let me know whether I can separate the channel RGB values using OpenGL. As I would like to touch some point of my textured plane and I am interested to know what is that RGB value of pixel at that point. I am not using mouse, I am using a haptic device to touch the plane. Thanks
05-23-2012, 08:30 PM
glReadPixels will allow you to read from the render buffer.
05-24-2012, 11:02 AM
Thanks for the reply. I have some simple question:
1) Do I need to use glOrtho to use glReadPixels; doesn't it work for gluPerspective;
2)Do I need to make the textured image mapped totally to the screen to use glReadPixels?
3) In the following formula:
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid* data);
x, y are the position of the current pixel,
width, height is ( 1, 1) if correspondsto 1 pixel, can it correspond to more than one, then what value will be retured for different RGB value?
It would be highly appreciated if my question is answered. Thanks in advance.
05-26-2012, 01:26 AM
1) mapping doesn't matter
2) you need to bind the buffer you wish to read; are you rendering to a frame buffer object? Is so, it must be bound for reading or read/write before you call glReadPixels. If not
glReadBuffer(GL_FRONT) reads the front buffer and glReadBuffer(GL_BACK) reads the back buffer.
3) checkout the full description of glReadPixels there are many options.
05-28-2012, 09:10 PM
Thanks for the reply. If some example codes are given for the different cases mention in (2), it would be easier for me to understand.
05-29-2012, 12:34 AM
Do you need an example for a frame buffer object or just the default render buffer?
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.