OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 18 Apr 2018 17:25:15 -0500Obtaining Euler angles from Rodrigues Rotation Matrixhttp://answers.opencv.org/question/189455/obtaining-euler-angles-from-rodrigues-rotation-matrix/ Hi,
I wish to extract Euler angles from the **rvec** output parameter of [cv::solvePnp](https://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#bool%20solvePnP(InputArray%20objectPoints,%20InputArray%20imagePoints,%20InputArray%20cameraMatrix,%20InputArray%20distCoeffs,%20OutputArray%20rvec,%20OutputArray%20tvec,%20bool%20useExtrinsicGuess,%20int%20flags)).
I understand that 3x1 rvec needs to be passed on to the [Rodrigues](https://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#void%20Rodrigues(InputArray%20src,%20OutputArray%20dst,%20OutputArray%20jacobian)) function to obtain the 3x3 rotation matrix.
But to obtain Euler Angles, I need to use a fixed convention ( see [this](https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix) , for example Z-Y-X,etc ) which requires the rotation matrix to be obtained from a **permutation (fixed order) of multiplication of Matrices** ,
**eg: for Z-Y-X convention,
R_resultant = Rz * Ry * Rx**.
I have looked into the source code [here](https://github.com/opencv/opencv/blob/master/modules/calib3d/src/calibration.cpp#L251) for Rodrigues function but don't quite understand how the matrix is formed Hence -
**My Question**: What is the **convention** (Z-Y-X, X-Y-Z, etc) of the formation of the 3x3 Rotation matrix obtained from Rodrigues ? Without this information I cannot obtain Euler angles. I have seen [this tutorial](https://github.com/opencv/opencv/blob/master/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp#L189) for real time pose estimation, but unfortunately I don't understand the assumption for the convention (and hence I had made another question for that - [here](http://answers.opencv.org/question/189414/issue-in-opencv-sample-tutorial-for-real-time-pose-estimation/?comment=189453#post-id-189453)).Mon, 16 Apr 2018 10:54:16 -0500http://answers.opencv.org/question/189455/obtaining-euler-angles-from-rodrigues-rotation-matrix/Answer by Tetragramm for <p>Hi,</p>
<p>I wish to extract Euler angles from the <strong>rvec</strong> output parameter of <a href="https://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#bool%20solvePnP(InputArray%20objectPoints,%20InputArray%20imagePoints,%20InputArray%20cameraMatrix,%20InputArray%20distCoeffs,%20OutputArray%20rvec,%20OutputArray%20tvec,%20bool%20useExtrinsicGuess,%20int%20flags)">cv::solvePnp</a>.</p>
<p>I understand that 3x1 rvec needs to be passed on to the <a href="https://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#void%20Rodrigues(InputArray%20src,%20OutputArray%20dst,%20OutputArray%20jacobian)">Rodrigues</a> function to obtain the 3x3 rotation matrix.</p>
<p>But to obtain Euler Angles, I need to use a fixed convention ( see <a href="https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix">this</a> , for example Z-Y-X,etc ) which requires the rotation matrix to be obtained from a <strong>permutation (fixed order) of multiplication of Matrices</strong> ,</p>
<p><strong>eg: for Z-Y-X convention,
R_resultant = Rz * Ry * Rx</strong>.</p>
<p>I have looked into the source code <a href="https://github.com/opencv/opencv/blob/master/modules/calib3d/src/calibration.cpp#L251">here</a> for Rodrigues function but don't quite understand how the matrix is formed Hence -</p>
<p><strong>My Question</strong>: What is the <strong>convention</strong> (Z-Y-X, X-Y-Z, etc) of the formation of the 3x3 Rotation matrix obtained from Rodrigues ? Without this information I cannot obtain Euler angles. I have seen <a href="https://github.com/opencv/opencv/blob/master/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp#L189">this tutorial</a> for real time pose estimation, but unfortunately I don't understand the assumption for the convention (and hence I had made another question for that - <a href="http://answers.opencv.org/question/189414/issue-in-opencv-sample-tutorial-for-real-time-pose-estimation/?comment=189453#post-id-189453">here</a>).</p>
http://answers.opencv.org/question/189455/obtaining-euler-angles-from-rodrigues-rotation-matrix/?answer=189483#post-id-189483Good news! A rotation matrix is a rotation matrix is a rotation matrix. A rotation can be represented by several different conventions of euler angles, ex, the Z-X-Y, ect. However, if they represent the same rotation, the produce the same rotation matrix. It is different matrices multiplied together in a different order, but the same end result.
What that means for you, is that you can decompose the rotation matrix to your heart's content without worrying about how the Rodrigues function works.Mon, 16 Apr 2018 20:06:22 -0500http://answers.opencv.org/question/189455/obtaining-euler-angles-from-rodrigues-rotation-matrix/?answer=189483#post-id-189483Comment by Tetragramm for <p>Good news! A rotation matrix is a rotation matrix is a rotation matrix. A rotation can be represented by several different conventions of euler angles, ex, the Z-X-Y, ect. However, if they represent the same rotation, the produce the same rotation matrix. It is different matrices multiplied together in a different order, but the same end result.</p>
<p>What that means for you, is that you can decompose the rotation matrix to your heart's content without worrying about how the Rodrigues function works.</p>
http://answers.opencv.org/question/189455/obtaining-euler-angles-from-rodrigues-rotation-matrix/?comment=189658#post-id-189658Absolutely not. I mean R_resultant = Rx1*Ry1*Rz1 = Rz2*Ry2*Rx2 = ... Rx1 will not equal Rx2 and so forth.
You simply choose which set of euler angles to decompose it into, and then do so. Your question is wrong. The convention (Z-Y-X, X-Y-Z) is not in the formation of the rotation matrix, it is in the formation of the euler angles. The Rotation matrix is complete, with no convention, or assumptions, or extra information needed.
You can decompose the same rotation matrix into Z-Y-X euler angles, and X-Y-Z euler angles and every other type. The resulting angles will be different, but they are the same rotation.Wed, 18 Apr 2018 17:25:15 -0500http://answers.opencv.org/question/189455/obtaining-euler-angles-from-rodrigues-rotation-matrix/?comment=189658#post-id-189658Comment by malharjajoo for <p>Good news! A rotation matrix is a rotation matrix is a rotation matrix. A rotation can be represented by several different conventions of euler angles, ex, the Z-X-Y, ect. However, if they represent the same rotation, the produce the same rotation matrix. It is different matrices multiplied together in a different order, but the same end result.</p>
<p>What that means for you, is that you can decompose the rotation matrix to your heart's content without worrying about how the Rodrigues function works.</p>
http://answers.opencv.org/question/189455/obtaining-euler-angles-from-rodrigues-rotation-matrix/?comment=189531#post-id-189531Thanks for answering! you mean R_resultant = RxRyRz = RzRyRx = all other x,y,z permutations etc ?Tue, 17 Apr 2018 08:30:08 -0500http://answers.opencv.org/question/189455/obtaining-euler-angles-from-rodrigues-rotation-matrix/?comment=189531#post-id-189531