use data from opencv to move opengl 3D model

hi all,

I’m doing my graphic project that uses both opengl and opencv.
I have done doing the opencv part that is to track hand movement by finding the center of the hand that appear in front of the camera (lets just call it a blob).

from there, I will get the center of the blob.

now, i want to make the 3D model in opengl move according to the center the blob from my opencv program.

the problem is when I combine both coding in one program,
only one of them will function.

example:

  1. both opencv and opengl window will appear, but image captured from the camera did not move.

  2. my opencv program running smoothly but when I hit ‘esc’ button, opengl window will appear and my opencv program stop running.

When I gone through the code, I think the glutMainLoop() function is the caused of this problem. but I don’t know how to fix it.
can someone help me?

this is the structure of my code.

–declaration–
int main()
{
<preprocessing>
initializing opengl 3D model

while(not ‘esc’)
{
- opencv process to detect hand movement.
- get the center of the blob
- update the position of the 3D model
}

glutMainLoop()
}

thank you.

Not directly related with OpenGL itself, you have a Glut problem :
Glut is event-driven, and can not work with your while() loop.
Instead of glut you can use GLFW, which is not event-driven, and will work seamlessly with your current algorithm, with something like :


  while(not 'esc')
  {
     - opencv process to detect hand movement.
     - get the center of the blob
     - update the position of the 3D model
     - GL command to drawn the model
     - glfwSwapBuffers() to show the display changes.
  }

The alternative if you want to stick with glut is to move the inside of the while loop to the glut display callback, and call glutPostRedisplay and the end of this callback. But unless you really understood this callback/postRedisplay stuff, I adwise you to try GLFW.

Hi ZbuffeR, thanks for your reply :slight_smile:

lets say I have done doing an opengl game in glut.
if i want to use the GLFW, that means i have to change the whole glut function to glfw?

is there many differences between glut and glfw?

from what i read about hacking glut here
is it by using this can also the problem?

Just RTFM the GLFW User Guide, I found it very easy to use after Glut.

lets say I have done doing an opengl game in glut.
if i want to use the GLFW, that means i have to change the whole glut function to glfw?

For a game, GLFW is way better than Glut.
Glut is good for simple demos, simple menus, a few keystrokes. It is not really game oriented.

Count the (probably low) number of glut* methods you use, it is not a complex change to do. Just be sure you understand how to convert each to equivalent GLFW code.

Otherwise, ask here :slight_smile:

ok, i’ll try it first. thanks! :smiley: