# Generation of a Transformation Matrix

Hi :) I need your help. I want to generate a 4x4 Transformation Matrix out of the StereoCalibration Process. So the Stereo/Rectification Process returns a 3x3 Rotation Matrix R and a 3x1 Translation Matrix T. How can I now transform a Point of Cam#1 to the coordinate system of Cam#2. I tried several things - but nothing worked for me. For example - following 4x4 Matrix:

R R R T

R R R T

R R R T

0 0 0 1

And multiplicated a 3D Points of Cam1 with the Matrix.

Again - I want to transform a 3D Point of Cam#1 (e.g. 1|0|0) to the coordinate System of the second Matrix. I hope you can help me :)

Thank you very much!

edit retag close merge delete

Sort by » oldest newest most voted

in general, you multiply a Mat by a row-vector, and receive a transformed col-vector.

vc = M * vr;


you could setup your Mat in the usual way, Mat m(4,4,CV32F); and assign one element after the other, but in this case you might want to profit from the ease of Mat_:

Mat m = (Mat_<float>(4,4) << 1,0,0,3,
0,1,0,3,
0,0,1,3,
0,0,0,1 );

// opencv can only multiply Mat's, so make one for the input vec (1,2,3):
Mat v = (Mat_<float>(4,1) << 1,2,3,1);  // note: 1 as last element
Mat r = m*v;
cerr << r << endl;


[4; 5; 6; 1]

more

Oh ok - thank you very much. But the multiplication was not the problem. But I think I know now a possible Problem.

How does OpenCV choose the coordinate system? z is for sure in the direction into the scene. But in which directions the x- and y-axis are looking?

Thank you very much :)

And where is the origin of the transfromation? It is in the center of the image?

• "right hand" system, z points out of the scene, x right, y up.
• a transformationmatrix does not have an origin, but the input or output coord-system have one, since x ynd y are derived from the image, that would be top-left, not center

Ok thank you very much. I will play a bit when I am @home. I will cry if I need help :D

Official site

GitHub

Wiki

Documentation