Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get Euler angles? #16

Open
chen1169968275 opened this issue Aug 16, 2016 · 6 comments
Open

How to get Euler angles? #16

chen1169968275 opened this issue Aug 16, 2016 · 6 comments

Comments

@chen1169968275
Copy link

No description provided.

@chen1169968275 chen1169968275 changed the title to How to get Euler angles? Aug 16, 2016
@chen1169968275
Copy link
Author

As your code in HeadPoseEstimation::pose(), after you get the rvec or pose matrix , how to get the face real Euler angles?(the value of yaw, pitch and roll)

@alexis-jacq
Copy link
Contributor

alexis-jacq commented Aug 16, 2016

Thankyou for your interest !

We use ROS TF library to do it. You can see in src/ros_head_pose_estimator.cpp the following lines :

        auto poses = estimator.poses();
[...]
        tf::Quaternion qrot;
        tf::Matrix3x3 mrot(
                trans(0,0), trans(0,1), trans(0,2),
                trans(1,0), trans(1,1), trans(1,2),
                trans(2,0), trans(2,1), trans(2,2));
        mrot.getRotation(qrot);
        face_pose.setRotation(qrot);

qrot is a quaternion, if you want euler angles you can use the matrix mrot as follow:

double roll, pitch, yaw;
mrot.getRPY(roll, pitch, yaw);

Please also have a look to our new package OpenFace Tracker, the head pose estimation is much more robust !

@chen1169968275
Copy link
Author

chen1169968275 commented Aug 17, 2016

Thanks for your reply.
With ROS TF Library, as your codes, I can get the Euler angles.
But there is another problem. If I cannot use ROS TF library, we get the rvec matrix after solvePnP() function, I don't know weather the rvec matrix is the 3D rotation matrix or not. If so, can I get the Euler angles with OPENCV's api decomposeProjectionMatrix to get the Euler angles?

@alexis-jacq
Copy link
Contributor

alexis-jacq commented Aug 17, 2016

rvec is a rotation vector (output of solvePNP), we use an OPENCV function "Rodigues" to get the 3x3 rotation matrix given this vector.
Then, you can use OPENCV's decomposeProjectionMatrix to get Euler angles.

@chen1169968275
Copy link
Author

Thanks.
So I do as follows:

cv::Mat rvec, tvec;
solvePnP(head_points, detected_points, projection, cv:;noArray(), rvec, tvec, false, cv::ITERATIVE);
cv::Mat rodrigues_rvec;
cv::Rodrigues(rvec, rodrigues_rvec);
cv::Mat cameraMatrix, rotMatrix, transVect, rotMatrixX, rotMatrixY, rotMatrixZ;
cv::Vec3d eulerAngles;
double* _r = rodrigues_rvec.ptr();
double projMatrix[12] = {_r[0], _r[1], _r[2], 0, _r[3], _r[4], _r[5], 0, _r[6], _r[7], _r[8], _r[9], 0};
cv::decomposeProjectionMatrix(cv::Mat(3,4,CV_64FC1,projMatrix, cameraMatrix, rotMatrix, transVect, rotMatrixX, rotMatrixY, rotMatrixZ, eulerAngles);

After that , the 3 value of eulerAngles can reach 100+ or smaller than -100, I cannot understand what does the values mean.
If possible, can you update your samples/head_pose_estimation_test.cpp with show the face's Euler angles.

@KeyKy
Copy link

KeyKy commented Feb 18, 2020

@chen1169968275 do you solved this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants