Wasim Karani
Wasim Karani

Reputation: 8886

OpenCV and OpenGL scale

Based on Opencv tracking I am trying to overlay object in openGL, but I see that OpenCV works on pixel values and OpenGL works on OpenGL units.

My window size for now is 320 x 240.
I know that I will have to define some thing so that synchronization is achieved between tracking and overlay. When I am changing positiony in OpenGL function glTranslatef (positionx, positiony, positionz); by just 1 pixel (i.e. 1 OpenGL Unit) I am getting huge difference in overlay object...

I think the problem is with the synchronization Of Opencv and OpenGL scale....

Upvotes: 0

Views: 419

Answers (1)

Ani
Ani

Reputation: 10906

You need to use a screen-aligned orthographic projection to map OpenGL units 1:1 with screen pixels.

    glViewport(0,0,320,240);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0,320,0,240,0,1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

Hope this helps!

Upvotes: 1

Related Questions