I got a question about how to use the EulerAngle to determine camera's orientation First, I used solvePnP function and got two output "rvec" and "tvec", then I use Rodrigues to convert rvec to rotation matrix "R". After that, I calculated EulerAngle by using the function below:
void getEulerAngles(cv::Mat matrix)
{
assert(isRotationMatrix(matrix));
float sy=sqrt(matrix.at<double>(0,0)*matrix.at<double>(0,0)+matrix.at<double>(1,0)*matrix.at<double>(1,0));
bool singular = sy<1e-6;
float theta_x=0.0,theta_y=0.0,theta_z=0.0;//theta_x means rotation around X-Axis
if(!singular)
{
theta_x=atan2(matrix.at<double>(2,1),matrix.at<double>(2,2));
theta_x= theta_x*180.0/3.1416 ;
theta_y=atan2(-matrix.at<double>(2,0), sy);
theta_y= theta_y*180.0/3.1416 ;
theta_z=atan2(matrix.at<double>(1,0), matrix.at<double>(0,0));
theta_z= theta_z*180.0/3.1416 ;
}
else
{
theta_x=atan2(-matrix.at<double>(1,2), matrix.at<double>(1,1));
theta_x= theta_x*180.0/3.1416 ;
theta_y=atan2(-matrix.at<double>(2,0), sy);
theta_y= theta_y*180.0/3.1416 ;
theta_z=0;
theta_z= theta_z*180.0/3.1416 ;
}
I know that different rotation order can make different result.So if I want to get the camera's orientation what kind of rotation order should I choose?