Convert OpenCV intrinsic camera matrix and extrinsic camera matrix to OpenGL PROJECTION matrix and MODELVIEW matrix

Tweet


Intrinsic parameters and PROJECTION matrix

Suppose that OpenCV camera intrinsice matrix is expressed as follows.

W: Horizontal pixel numbers of the image
H: Vertical pixel numbers of the image
fx: Focal length of horizontal direction
fy: Focal length of vertical direction
Here, we assume that the camera center is in the middled of the image. For other cases, please adequetely revise by yourself.

OpenGL PROJECTION matrix will be as follows.

zn: Distance of front clipping plane (e.g. 0.1)
zf: Distance of back clipping plane (e.g. 1000)

The correspondence between OpenGL matrix double pm[16] should be as follows.

In some cases with a certain other coordinate system, the abovementioned matrix may not work well. In such cases, please adequetely revise by yourself.


Extrinsic parameters and MODELVIEW matrix

Suppose that OpenCV camera extrinsice matrix is expressed as follows.

OpenGL MODELVIEW matrix will be as follows.

or

Which one of the above two is adequate depends on the coordinate system.

The correspondence between OpenGL matrix vm[16] should be as follows.

In some cases with a certain other coordinate system, neither of the abovementioned two matrices may not work well. In such cases, please adequetely revise by yourself.


Back