PDA

View Full Version : A simple question on matrix in opengl and opencv



ssyybbyy
05-07-2014, 07:27 PM
I have some code which has matrix in opencv. Now I would like to use opengl for further modeling. Suppose I have the following matrix:

double mat[16] = { 1.0, 0.0, -a, 0.0, 0.0, 1.0, -b, 0.0, 0.0, 0.0, -c, 0.0, 0.0, 0.0, 0.0, 1.0};

I think opengl use column major order as follows:

1.0 0.0 0.0 0.0
0.0 1.0 0.0 0.0
-a -b -c 0.0
0.0 0.0 0.0 1.0

whereas opencv use the row major order as follows:

1.0 0.0 -a 0.0
0.0 1.0 -b 0.0
0.0 0.0 -c 0.0
0.0 0.0 0.0 1.0

Please let me know if i am not right.

GClements
05-09-2014, 05:00 PM
OpenGL uses column-major order by default (the "transpose" versions of functions use row-major order). OpenCV uses row-major order by default, but can use column-major order (the stride or step for each dimension can be set explicitly).

However, if your example matrix was supposed to be a translation, it's transposed (also, the wrong column is used). A matrix for a translation by the vector (x,y,z) looks like:


1 0 0 x
0 1 0 y
0 0 1 z
0 0 0 1

ssyybbyy
05-13-2014, 07:02 PM
Actually, the matrix is not a translation matrix, it is a rotation matrix. Apart from row-major and column-major order, is there any other difference due to the coordinate system? Please let me know.