Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV to OpenGL coordinate system transform

Tags:

I have two right handed coordinate systems.

OpenCV enter image description here

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

enter image description here

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.

like image 405
Carpetfizz Avatar asked Jun 05 '17 18:06

Carpetfizz


People also ask

Is OpenCV left handed?

OpenCV coordinate system is right-handed, the answer here gives an illustrative example about OpenCV camera system.

Is OpenCV right handed?

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.

What is the coordinate system for OpenGL?

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.


1 Answers

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. two coordinate systems

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. two view matrices

like image 51
Summer Sun Avatar answered Sep 25 '22 13:09

Summer Sun