问题
I am using two image of the single object the object is roated certain degree from its first image.
I have calculated the POSE of each image and converted the rotational vector to Matrix using Rodergues(). Now how do I calculate and see how much it is rotated from its first position?
I have tried many ways but answers was no were close
EDIT: My camera is fixed only the object is moving.
回答1:
We can get Euler angles from rotation matrix using following formula.
Given a 3×3 rotation matrix
The 3 Euler angles are
Here atan2 is the same arc tangent function, with quadrant checking, you typically find in C or Matlab.
Note: Care must be taken if the angle around the y-axis is exactly +/-90°. In that case all elements in the first column and last row, except the one in the lower corner, which is either 1 or -1, will be 0 (cos(1)=0). One solution would be to fix the rotation around the x-axis at 180° and compute the angle around the z-axis from: atan2(r_12, -r_22).
See also https://www.geometrictools.com/Documentation/EulerAngles.pdf, which includes implementations for six different orders of Euler angles.
回答2:
If R is the (3x3) rotation matrix, then the angle of rotation will be acos((tr(R)-1)/2), where tr(R) is the trace of the matrix (i.e. the sum of the diagonal elements).
That is what you asked for; I estimate a 90% chance that it is not what you want.
回答3:
For your reference, this code computes the Euler angles in MATLAB:
function Eul = RotMat2Euler(R)
if R(1,3) == 1 | R(1,3) == -1
%special case
E3 = 0; %set arbitrarily
dlta = atan2(R(1,2),R(1,3));
if R(1,3) == -1
E2 = pi/2;
E1 = E3 + dlta;
else
E2 = -pi/2;
E1 = -E3 + dlta;
end
else
E2 = - asin(R(1,3));
E1 = atan2(R(2,3)/cos(E2), R(3,3)/cos(E2));
E3 = atan2(R(1,2)/cos(E2), R(1,1)/cos(E2));
end
Eul = [E1 E2 E3];
Code provided by Graham Taylor, Geoff Hinton and Sam Roweis. For more information, see here
回答4:
Let R1c and R2c be the 2 rotation matrices you have computed. These express the rotations from the object in poses 1 and 2 respectively to the camera frame (hence the second c suffix). The rotation matrix you want is from pose 1 to pose 2, i.e. R12. To compute it you must rotate, in your mind, the object from pose_1-to-camera, then from the camera-to-pose_2. The latter rotation is the inverse of the pose_2-to-camera espressed by R2c, hence:
R12 = R1c * inv(R2c)
From matrix R12 you can then compute the angle and axis of rotation using Rodiguez's formula.
来源:https://stackoverflow.com/questions/15022630/how-to-calculate-the-angle-from-rotation-matrix