Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain Rotation Axis from Rotation Matrix and translation vector in OpenCV

I have a chessboard in two images with some angle of rotation. Lets find the rotation angle of second image with reference of first image.

For that I found the Rotation Matrix (3x3) and translation matrix (3x1) of those objects.

How can I find the Rotation Angle and Rotation Axis of object using those matrices?

like image 844
aranga Avatar asked Sep 17 '12 16:09

aranga


People also ask

How do you find the rotation of a vector along the rotation matrix?

To find the rotation of a vector we simply multiply the required rotation matrix with the coordinates of the given vector. In 2D space, this is given by ⎡⎢⎣x′y′⎤⎥⎦ [ x ′ y ′ ] = ⎡⎢⎣cosθ−sinθsinθcosθ⎤⎥⎦ [ c o s θ − s i n θ s i n θ c o s θ ] ⎡⎢⎣xy⎤⎥⎦ [ x y ] .

How do you combine translation and rotation matrix?

A rotation matrix and a translation matrix can be combined into a single matrix as follows, where the r's in the upper-left 3-by-3 matrix form a rotation and p, q and r form a translation vector. This matrix represents rotations followed by a translation.

How do you find the rotation of a vector?

cosθ = (r11 + r22 + r33 − 1)/2 . If sinθ = 0, and cosθ = 1 then the rotation vector is r = 0 .


2 Answers

For every type of conversion between rotation representations you have this website euclidean space.

You will find theory and code samples of:

  • Rotation matrix to quaternion: link

  • Quaternion to axis angle: link

  • Rotations in general and all representations: link

And in relation to your question you have Axis Angle. If you have the rotation matrix R (3x3), you can obtain the angle and axis this way (see Matrix to Axis Angle):

  • angle = acos(( R00 + R11 + R22 - 1)/2);

  • Axis x,y,x:

    x = (R21 - R12)/sqrt((R21 - R12)^2+(R02 - R20)^2+(R10 - R01)^2);

    y = (R02 - R20)/sqrt((R21 - R12)^2+(R02 - R20)^2+(R10 - R01)^2);

    z = (R10 - R01)/sqrt((R21 - R12)^2+(R02 - R20)^2+(R10 - R01)^2);

like image 60
Jav_Rock Avatar answered Sep 28 '22 18:09

Jav_Rock


Already working wih openCV I would rcommend using the Rodrigues method: cv::Rodrigues(src, dst, jacobian), that computes the rotation vector if you have a rotation matrix for an argument and vice versa.

like image 44
jochen Avatar answered Sep 28 '22 16:09

jochen