OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Mon, 16 Apr 2018 10:54:16 -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)).malharjajooMon, 16 Apr 2018 10:54:16 -0500http://answers.opencv.org/question/189455/Issue in OpenCV sample tutorial for real time pose estimationhttp://answers.opencv.org/question/189414/issue-in-opencv-sample-tutorial-for-real-time-pose-estimation/Hi,
I was trying out the real time pose estimation tutorial from OpenCV ( [this tutorial](https://docs.opencv.org/3.3.0/dc/d2c/tutorial_real_time_pose.html) ), and while looking into the source code, I may have found a (possible) inconsistency -
The functions for converting between Rotation Matrix and Euler Angles ( please see [euler2rot](https://github.com/opencv/opencv/blob/master/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp#L229) and [rot2euler](https://github.com/opencv/opencv/blob/master/samples/cpp/tutorial_code/calib3d/real_time_pose_estimation/src/Utils.cpp#L189) from the C++ source code for the tutorial).
I am aware that there are **6-types** of [Tait-bryan](https://en.wikipedia.org/wiki/Euler_angles) angles (they are colloquially referred to as **Euler Angles** ).
**My issue:**
- The above source code functions **do not** adhere to any of the 6 types. I checked a few sources to verify this -
From the [section on wikipedia page](https://en.wikipedia.org/wiki/Euler_angles#Rotation_matrix) and even wrote a simple Matlab script using symbolic variables ( please see below, at the end of the question ).
- **The source code in the functions seems to correspond to the Y-Z-X Tait bryan angles, but with the pitch and yaw interchanged.** Why is this the case ? (Does this have something to do with the fact that the camera's coordinate axes has z-facing forward, y-facing downward and x-facing right ? )
- And finally, I think, Z-Y-X Tait Bryan angles are the industry standard for robotics , hence is there any particular reason for using Y-Z-X (with the pitch and yaw interchanged, as noticed above) ?
**================= Matlab script below for reference ============**
syms roll
syms pitch
syms yaw
Rx = [1 0 0; 0 cos(roll) -sin(roll); 0 sin(roll) cos(roll)];
Ry = [cos(pitch) 0 sin(pitch); 0 1 0; -sin(pitch) 0 cos(pitch)];
Rz = [cos(yaw) -sin(yaw) 0; sin(yaw) cos(yaw) 0; 0 0 1];
R_Y_Z_X = Ry * Rz * Rx
**Output**:
R_Y_Z_X =
[ cos(pitch)*cos(yaw), sin(pitch)*sin(roll) - cos(pitch)*cos(roll)*sin(yaw), cos(roll)*sin(pitch) + cos(pitch)*sin(roll)*sin(yaw)]
[ sin(yaw), cos(roll)*cos(yaw), -cos(yaw)*sin(roll)]
[ -cos(yaw)*sin(pitch), cos(pitch)*sin(roll) + cos(roll)*sin(pitch)*sin(yaw), cos(pitch)*cos(roll) - sin(pitch)*sin(roll)*sin(yaw)]malharjajooSun, 15 Apr 2018 19:31:39 -0500http://answers.opencv.org/question/189414/How can I get rotation-vector from Euler-angles?http://answers.opencv.org/question/88531/how-can-i-get-rotation-vector-from-euler-angles/If I have 3 Euler-angles then how can I get rotation-vector to use it for camera-rotation in [OpenCV-viz3d](http://docs.opencv.org/2.4/modules/viz/doc/viz3d.html#)?
I.e. how can I get `Vec3d( X, Y, Z)` from [Euler-angles](https://en.wikipedia.org/wiki/Euler_angles) (alfa, betta, gamma) to use in this code?
viz::Viz3d viz_3d_window("Viz window");
cv::Affine3d pose = viz_3d_window.getViewerPose();
viz_3d_window.setViewerPose( pose.rotate( Vec3d( X, Y, Z) ) );
cv::Affine3d::rotate(); https://github.com/Itseez/opencv/blob/f9e2b036a502309c0da5abc5e711d4cd64eb8a38/modules/core/include/opencv2/core/affine.hpp#L114
I can find Euler-angles from rotation-matrix by using [RQDecomp3x3()](http://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html?highlight=euler#rqdecomp3x3) or as shown in [that question](http://answers.opencv.org/question/8842/rotation-matrix-to-euler-angle/), but whether is there an inverse function in the OpenCV to find rotation-matrix from Euler-angles or better to find rotation-vector( `Vec3d( X, Y, Z)` )?AlexBThu, 25 Feb 2016 03:05:56 -0600http://answers.opencv.org/question/88531/Kalman filtration for rotationhttp://answers.opencv.org/question/18186/kalman-filtration-for-rotation/I want to use Kalman filter for rotation. I have rotation matrix, but i can't use filtration for it, because all it's elements interdependent. That's why i try to convert matrix to euler angles and to filter each of compoments.
My questions:
- is this filtering of euler angles will be right? (is all components x, y, z independent? I think no) If yes, how to avoid gimbal lock during filtration?
- is there a better way to filter the rotation?tenta4Mon, 05 Aug 2013 02:18:54 -0500http://answers.opencv.org/question/18186/