Sign in to follow this  
aseg

OpenGL Directshow/OpenCV with OpenGL

Recommended Posts

I would like to combine openGL with openCV What i would like to do is, capture using a webcam, a realworld image (this is simple and has been done with the help of openCV) Then draw, say a cube on the captured video image using OpenGl. Is there a way of doing this. Thanks...

Share this post


Link to post
Share on other sites
The NeHe tutorials.
Particularly lessons 1 and 6 (texture mapping). If you already have set up a buffer of bytes with the image in it, creating a texture will be easy.

You want to get the captured image into an OpenGL window, not the other way around. Importing the image to OpenGL is easy, exporting and drawing OpenGL rendered graphics in another environment... not so much.

Share this post


Link to post
Share on other sites
You may consider using escapi library. Essentially, it lets you use captured webcam data as texture data. This way you can use polygons to display webcam capture and easily draw whatever you want on top of them.

Things to note:
1. You must create the texture which displays webcam capture with glTexImage2D; you can't create mipmaps.

glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid*)capture.mTargetBuf);




2. "deinitCapture(device)" should be called before terminating application, otherwise nothing will show up next time you run your app.

Share this post


Link to post
Share on other sites
So this is what I did, based on the replies above:

//opencv code to capture a single frame :
CvCapture* capture = cvCaptureFromCAM( -1 );
IplImage* frame = cvQueryFrame( capture );

//use glTextImage2D :
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,320,240,0,GL_RGB,GL_UNSIGNED_BYTE, frame->imageData); // AN ERROR OCCURS HERE

I am getting the following error :

Error:Expression cannot be evaluated

i.e, The frame.height, frame.width, etc. are garbage values.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this