I have Matlab code that renders (albiet very slowly) 3d points from the POV of a camera that is based on a real camera. The data originated from a stereo capture, and preserving the original camera’s parameters is important. The camera model folows the opencv camera model:
The only difference is that I dont multiply by s, and do a divide by z afterwards, which works just as well.
Now, I have all the parameters, cx, cy, fx, fy, and the Rotation/Translation matrix. However, Im not sure how to use these parameters in OpenGL. I’ve tried fiddling around with glFrustum and gluPerspective. I’ve even tried loading the perspective matrix (the one with fx and cx parameters) via glMultMatrixd and glLoadMatrixd but i keep getting a black screen.
In short, how do I convert this camera model into something that opengl expects?
BTW It works fine in Matlab, so the camera model is fine.
I think that the simplest solution would be to write a vertex shader with glsl and perform your custom camera transformations.
If you want to use the fixed pipeline, you will have to rewrite your matrices before since opengl uses only 4x4 matrices.
[R|t] is the camera view transformation, consequently you can set the opengl modelview matrix with this one. Assuming transformed point are already in world space, it would look like this:
Actually, as I mentioned earlier, I already tried glLoadMatrix, precisely the way you mentioned. The model is already transformed correctly, and can be viewed fine with an orthographic camera, yet, the projection matrix produces a blank screen.
I think I have found the answer, however. For those of you facing a similar problem, it is explained in detail here:
I would like to report that after implementing the above technique myself I can safely say that it does work.
If you are getting a black screen, then first try setting your viewport to 0,0,screenwidth,screenheight (to make sure nothing is clipped out), and then rotating/transforming your model until you see something. This is likely because (as in my case) the camera follows a true pinhole camera model and the projection actually inverts the image, and the camera faces the oppossite direction (i.e, the image is formed behind the lense)…