I have two right handed coordinate systems.
OpenCV
As you can see with the black arrows, the camera looks down the positive $Z$ axis. You can ignore the rest of the diagram.
OpenGL
Although not visible here, the camera in OpenGL looks down the -Z
axis. I want to transform a 3D point in front of the camera in the OpenCV coordinate system to a 3D point in front of the camera in the OpenGL.
I'm trying to represent this in a 4x4 matrix that concatenates R
and T
with 0001
at the bottom.
So far, I've tried this
1 0 0 0
0 -1 0 0
0 0 -1 0
0 0 0 1
but it doesn't seem to do anything, nothing shows up in the OpenGL coordinate system.
OpenCV coordinate system is right-handed, the answer here gives an illustrative example about OpenCV camera system.
As we know, it's right- handed Cartesian coordinate in OpenGL. But in OpenCV, the X-axis turns towards right, Y-axis turns towards down, and Z-axis turns towards the inside of screen like Fig.
OpenGL requires x, y, z coordinates of vertices ranging from -1.0 to 1.0 in order to show up on the screen. Otherwise, any vertices that are outside of the clipping space will be clipped. There are two types of projection: orthographic and perspective projection.
The camera coordinates of OpenCV goes X right, Y down, Z forward. While the camera coordinates of OpenGL goes X right, Y up, Z inward.
Use solvePnP
as one of the most commonly used example.
You get a 3x3 rotation matrix R
and a 1x3 translation vector T
, and create a 4x4 view matrix M
with R
and T
. Simply inverse the 2nd and 3rd row of M and you will get a view matrix for OpenGL rendering.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With