Monday, April 28, 2008

CG Final Project: Augmented Reality

To simply the project, Dr. Eraldo let us to use Camera Calibration Toolbox for MATLAB and its dataset for the experiment, so we can use the calibration results directly. The toolbox works fine, but a tricky problem drove me crazy.

The basic idea is using the calibration results to:
(1) set up the OpenGL intrinsic parameters for the camera
(2) use the extrinsic parameters to pose the camera.

For problem (1), I tried to use ARToolkit's argConvGLcpara2 function to convert it into OpenGL projection matrix format. Then, I use the simplified version, using glFrustum instead.
Suppose the width and height of the image is 640, 480 and the focus length is 600, then we can safely set the frustum as
glFrustum(-320,320,-240,240,600, 100000);

Note that ARLib use a different unit! It normalize everything by the focal length. I spend a hell lot of time to figure this out.

This simplification works for modern cameras, whose skewness and aspect ratio and central deviation is very small.

For problem (2), it seems easy to load the GL_MODELVIEW matrix with some calculation. But with the data output from the Camera Calibration Toolbox, no existing formulations are right.

It's because that in this TOOLBOX, the camera coordinate system is different from OpenGL, where the z-axis is pointing on the opposite direction of the camera. So anther transformation should be considered to reverse z-axis and y-axis. I simply pull out a paper and worked out all the math to manually calculate the relationship between the view point, view direction and up vector to solve the problem.

















No comments: