Hi there!!
I’ve been working with OpenCV to capture images from a webcam and using its functions to proccess this images. I needed to detect a marker for which I used ARToolKit. Now, I need to draw a kind of blackboard according to the marker, for which I still need ARToolkit plus OpenGL for perspective transformation and so on.
I’ve already managed to use my captured frame as the background in an OpenGL window. I didn’t use GLUT, as GLUT has its own mainloop, so I used freeGLUT instead. What I am trying to do now is to draw on the background my “blackboard”.
This is the code I use to have the openCV image as background and works:
Initializing function:
int init(void)
{
//general initialization:
char cadena[25]="GestionMarcaAR\0";
char **argv;
int argc = 1;
argv=(char **)malloc(sizeof(char *));
*argv=(char *)malloc(sizeof(char)*10);
strcpy(*argv, cadena);
glutInit(&argc,argv); //we cheat it ;P
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(800, 400);
glutInitWindowSize(320,240);
glutCreateWindow("Name");
glutDisplayFunc(draw);
glutIdleFunc(draw);
//initializating the texture mapping
GLuint mTexture;
glGenTextures(1, &mTexture);
glBindTexture(GL_TEXTURE_2D, mTexture);
glEnable(GL_TEXTURE_2D);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
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
glColor3f(0.0f,0.0f,0.0f);
return 0;
}
Drawing function:
void draw()
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,320,240,0,GL_BGR,GL_UNSIGNED_BYTE, imagen->imageData);
glBegin(GL_POLYGON);
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);
glEnd();
glFlush();
glutSwapBuffers();
}
And what is needed to be anywhere in the mainloop of openCV:
glutPostRedisplay(); //to force "draw" function to be called
glutMainLoopEvent(); //freeglut function
Ok, fine. Now I try to add this code snippet which works propperly in the simple program, but doesn’t in my draw function:
double gl_para[16];
argDrawMode3D();
glClearDepth(1.0);
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
argConvGlpara(patt_trans,gl_para);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixd(gl_para);
glTranslatef(-270.0,0.0,0.0);
glEnable (GL_POLYGON_STIPPLE);
glPolygonStipple (eight);
glRectf (125.0, 25.0, 225.0, 125.0);
glDisable (GL_POLYGON_STIPPLE);
glFlush();
glDisable(GL_DEPTH_TEST);
glutSwapBuffers();
The problem is that my image gets stucked and doesn’t change and it’s because of “glLoadMatrixd(gl_para)”. Does anyone knows why is this happening?? Any ideas??
Thanks in advance