Internal parameters of the camera

How can I recover the focal length from the perspective projection matrix specified by gluPerspective(…) or glFrustum(…) or at all?

And how can I find out the paramters of the transformation from the normalized device coordinates into the window coordinates? (floating-point numbers <-> pixels)

Thanks a lot,

hns

Howdy,

waht i’d do:

refer to pg 480 of the red book for hte perspective and orthogonal projection matricies. elements 3,3 and 3,4 of the matricies give you the values of the near and far clipping planes. You just need to solve a pair of simultaneous eqns to find f and n. (The near clip plane is the focal length of the camera, ie. the distance from the image plane to the focal point).

I think I may have done this, once… if I could be bothered to walk upstairs to my vision office to get it if you’re having problems with it then I might work it out again…

hope this helps!

cheers,
John

HNS,

The transformation from NDC (normalized device coordinates) into window coordinates is simply a function of the viewport. That is, the viewport transform takes NDC into window space directly.

Xwin = ((Xndc+1)/2.0)*vp_width + vp_x
Ywin = ((Yndc+1)/2.0)*vp_height + vp_y

As for recovering the focal length, it is not really encoded in the viewing and projection transformations. If you were rendering a stereo image, or depth-of-field blurred image, you’d choose a focal length and rotate for each eye (for stereo) or jitter (for depth-of-field bluring). As it is everyting in the view volume is in perfect focus.

Hope this helps…
Cass

<splutters> what?! of COURSE the focal length in encoded in the projection matrix!! why on earth would you think it wasn’t?! The proj matrix is the model of the pin-hole camera, and all cameras need to know the distance from the image plane to the focal point!

from discrete maths, the “classic” pinhole camera is defined as

[ 1 0 0 0 ]
[ 0 1 0 0 ]
[ 0 0 f 0 ]

where f is the focal length. This stuff is also encoded in OpenGL’s proj matrix, although it does other tricky stuff…

cheers,
John

oh, and another thing to the original poster… there is more intrinsic parameters in a real camera than just the focal length. Like radial distortion and the optical centre. But these aren’t modelled by opengl. (well, the optical centre is )

cheers
John

John,

Of what value is the “focal length” you can back out of an OpenGL projection matrix if everything in the view volume is in perfect focus? I’m not sure I understand your point.

Cass

I don[t know what “value” it is? What do you mean? How useful is it to know the focal length? In OpeNGL, not very useful. But computer vision reseach also uses the pinhole camera model, and they find the focal length useful!! Yes, even the pinhole camera needs to know about focal length. (Why? well… hmm… the orthogonal proj matrix has an infinite focal length, and perspective cameras don’t. so… hmm

I don[t know why a graphics guy would want to know the focal length, ubt… there you go

cheers
John