Directshow/OpenCV with OpenGL

Started by
2 comments, last by aseg 16 years, 6 months ago
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...
Advertisement
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.
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.
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.

This topic is closed to new replies.

Advertisement