We are using Opengl for Computer Vision work. Doing this we encountered the following problem.
We don’t want to set view[point, camera etc. explicitely.
In image processing and computer vision we use 3x4 projection matrices §
to map from 3D (X,Y,Z,1) to image coordinates (x,y,1) as follows:
[ P11 P12 P13 P14 ] [ X ] [ x ]
[ P21 P22 P23 P24 ] [ Y ] = [ y ] ( ‘=’ is up to a scale factor)
[ P31 P32 P33 P34 ] [ Z ] [ 1 ] [ 1 ]
Where x = ((P11X+P12Y+P13Z+P14) / (P31X+P32Y+P33Z+P34)) is the image
x position and y is computed in a similar fashion.
Now what I would like to do is find the projection, viewport and modelview
parameters in opengl that correspond to an arbitrary projection matrix
NOTE: We already tried the following: First set the modelview matrix to identity. Then set the projection matrix:
[ P11 P12 P13 P14 ] [ X ] [ x ]
[ P21 P22 P23 P24 ] [ Y ] = [ y ] ( ‘=’ is up to a scale factor)
[ 0 0 0 1 ] [ Z ] [ z ]
[ P31 P32 P33 P34 ] [ 1 ] [ w ]
BUT: We forgot that we loose depth information this way in opengl.
Unfortunately it’s not quite that easy, as the projection matrix, P, that
I’ve got maps directly into image coordinates(!). This means that
(P11X+P12Y+P13Z+P14)/(P31X+P32Y+P33Z+P34)
is in image coordinates already and shouldn’t need a viewport
transformation to be applied to it.
Actually we can’t work out how to compute the ‘correct’ z-value.
And how to use it in opengl. What happens now is, that everything
is “projected” to a plane, so opengl has no depth information and
thus draws elements that should be hidden (in the back of the object).
Any help is highly appreciated!