View Full Version : OpenCV & OpenGL
Hi. How can I project the model created by OpenGL to the image loaded by OpenCV?
I used OpenCV to load an image (IplImage *src = cvLoadImage(argv),and separately I used OpenGL to create a model. But I want to project the model I created to that image and then do some other tasks by using OpenCV. I am a very beginner for both OpenGL and OpenCV. If anybody knows how to do it,please help me. Thank you.
If you don't need to do this task several times per frame, you could use glReadPixels. This reads your window (or a portion, whatever you ask for it) onto an off-screen buffer. I suppose you could then load this buffer into OpenCV. Remember to check the image storage type, such as byte, etc.
Thanks for your help. But I have to do that task many times per frame. Namely, I have to adjust the model -> project to the image -> do some Image processing process -> adjust the model -> project -> and so on. I have to do these process several times. Do you know how I can do it efficiently? Thank you.
11-09-2006, 10:11 AM
See, I am using OpenCV to process images captured form a webcam. But, I want to make drawings in this images with OpenGL. So, I found this functions, glDrawPixels and glReadPixels, that should help me getting my OpenCV image from and to OpenCV. But they are not working as I expected them to work.
I tried this simple code, I would like anyone to tell me what's wrong:
glClearColor (0.0, 0.0, 0.0, 0.0);
glColor3f (1.0, 1.0, 1.0);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
glVertex3f (0.25, 0.25, 0.0);
glVertex3f (0.75, 0.25, 0.0);
glVertex3f (0.75, 0.75, 0.0);
glVertex3f (0.25, 0.75, 0.0);
Are there any other ways to achive the same thing?
I'd appreciate any help. Thanks in advance.
11-20-2006, 09:03 AM
Hi there! :)
I finally made it, I have the OpenCV image in an OpenGL window. That's not what I wanted, but that's the best I can get. I didn't use GLUT, as GLUT has its own mainloop, so I used freeGLUT instead. Here is the code.
int argc = 1;
argv=(char **)malloc(sizeof(char *));
glutInit(&argc,argv); //we cheat it ;P
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
//initializating the texture mapping
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); //color blanco de fondo
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,320,240,0,GL_BGR,GL_UNSIGNED_BYTE, imagen->imageData);
glTexCoord2f(0.0f, 0.0f); glVertex2f(-1.0f, -1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f( 1.0f, -1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f( 1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex2f(-1.0f, 1.0f);
}And what is needed to be anywhere in the mainloop of openCV:
glutMainLoopEvent(); //freeglut function
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.