Created
July 25, 2019 06:56
-
-
Save davegreenwood/3a32d779f81f08dce32f3bb423672191 to your computer and use it in GitHub Desktop.
OpenCV to OpenGL projection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How to get the proper OpenGL projection matrix from the OpenCV camera calibration values? | |
For the simple common case where the OpenCV camera matrix has the form: | |
|fx 0 cx| | |
|0 fy cy| | |
|0 0 1| | |
The corresponding OpenGL projection matrix can be computed like this: | |
m[0][0] = 2.0 * fx / width; | |
m[0][1] = 0.0; | |
m[0][2] = 0.0; | |
m[0][3] = 0.0; | |
m[1][0] = 0.0; | |
m[1][1] = -2.0 * fy / height; | |
m[1][2] = 0.0; | |
m[1][3] = 0.0; | |
m[2][0] = 1.0 - 2.0 * cx / width; | |
m[2][1] = 2.0 * cy / height - 1.0; | |
m[2][2] = (zfar + znear) / (znear - zfar); | |
m[2][3] = -1.0; | |
m[3][0] = 0.0; | |
m[3][1] = 0.0; | |
m[3][2] = 2.0 * zfar * znear / (znear - zfar); | |
m[3][3] = 0.0; | |
Where height and width are the size of the captured image ; znear and zfar are the clipping value for the projection. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment