Open chen1169968275 opened 8 years ago
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 !
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?
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.
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.
@chen1169968275 do you solved this?
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)