How to convert rvects to rotation matrix?

I have successfully calibrated a camera using this link:
openCV camera Calibration

I get the camera matrix, distortion coefficients, rotation vectors (rvects) and translation vectors (tvects). However, the rvects and tvects are a long list of arrays and I would like the rotation matrix and transformation matrix instead.

How would I go about converting the rvects array to a rotation matrix and the tvects array to a transformation matrix?

I found that it could be done using ‘Rodrigues’ but I am unsure exactly how this is done. Some clarification would be great, thanks.

Below is the data after running the camera calibration using OpenCV:

Camera matrix :

[[1.44644326e+03 0.00000000e+00 9.59836634e+02]
[0.00000000e+00 1.44646498e+03 5.39556895e+02]
[0.00000000e+00 0.00000000e+00 1.00000000e+00]]

dist :

[[ 6.95929106e-06 -2.00836991e-04 8.42048176e-06 2.98005924e-05
3.04891387e-04]]

rvecs :

[array([[0.10322433],
[0.00586084],
[0.01965572]]), array([[ 0.02876875],
[-0.03474045],
[ 0.01824509]]), array([[ 0.03467534],
[-0.05020887],
[ 0.01830534]]), array([[ 0.03556834],
[-0.05399128],
[-0.0484105 ]]), array([[ 0.03717584],
[ 0.08012789],
[-0.04607123]]), array([[ 0.01846599],
[-0.11597159],
[-0.05320749]]), array([[ 0.10165191],
[-0.07348809],
[ 0.02913424]]), array([[-0.05693991],
[-0.011658 ],
[ 0.01366273]]), array([[ 0.30802603],
[-0.10069939],
[ 0.10513563]]), array([[0.0610907 ],
[0.44109706],
[0.11019328]]), array([[-0.19697588],
[-0.04283537],
[ 0.03067312]])
 ...
 ...
 ...


tvecs :

[array([[ 2.66476989],
[-3.33673936],
[17.85376573]]), array([[-4.8351615 ],
[ 0.55764164],
[18.24433871]]), array([[-9.69708746],
[-4.47578088],
[16.45470293]]), array([[-10.84578967],
[ -7.83191025],
[ 25.7312514 ]]), array([[ 8.33363135],
[-4.864706 ],
[27.99576755]]), array([[-8.31158562],
[ 0.06787774],
[23.34155579]]), array([[-11.63857256],
[ 2.74490915],
[ 23.75431658]]), array([[-0.70765791],
[ 3.80631702],
[28.47027191]]), array([[-14.7612401],
[ -0.32354 ],
[ 25.6419018]])
 ...
 ...
 ...

Below is the desired data (condensed matrix instead of rvects and tvects for each frame)

[
{
'id': 3, // optional
'R': [ /* 3x3 rotation matrix */ ],
'k': [ /* 3x3 calibration/instrinsics matrix */ ],
't': [ /* 3x1 translation matrix */ ],
'dist': [ /* 5x1 distortion coefficients */ ]
}.
]

the lists of rvecs and tvecs correspond to the input pictures. each picture has one rvec and one tvec.

a 3x1 matrix is technically a matrix, but it’s really a “vector”.

the tvec is a vector defining the required translation.

the rvec is a vector representing the rotation axis, and its length encodes the angle in radians to rotate. the Rodrigues method turns such a rotation vector into a 3x3 matrix.

if you want a composite matrix, it will be 4x4 (3 space dimensions + 1 projective space dimension). it starts as a 4x4 identity, but then you set the upper left 3x3 part to be the 3x3 rotation matrix, and you set the top right 3x1 part to be the translation vector. this 4x4 transformation matrix applies the rotation and then the translation.

Thanks for the explanation @crackwitz

Are there some detailed steps on how to use the Rodrigues method to generate a 3x3 rotation matrix and 3x1 translation matrix using rvecs and tvecs?

I am new to OpenCV and camera calibration details.
Any help would be great, thanks.

the Rodrigues API only deals with rotation, not translation.

OpenCV has documentation at docs.opencv.org

Camera calibration and 3D reconstruction

Rodrigues procedure

as for book recommendations, there’s the hartley n zisserman book, “multi view geometry”
https://www.robots.ox.ac.uk/~vgg/hzbook/hzbook1.html

Hello! I have the same question, but I don’t know what rotation vector I should use (Which from the array of rvecs) to get a rotation matrix.
Are there any criteria to decide?

Thanks for your time.

those transformations are wrt to the calibration boards, one r,t for each image in the calibration. what do you expect to do with them ?

  • you cannot make a single transformation from it
  • once you finished the calibration (and put the board away), they’re probably meaningless
1 Like