code

/*
* File : haedPose.cpp
* Coder:
* Date : 20181126
* Refer: https://www.learnopencv.com/head-pose-estimation-using-opencv-and-dlib/
*/ #include <opencv2/opencv.hpp>
#include <Eigen/Eigen> using namespace std;
using namespace cv; int main(int argc, char **argv)
{ // Read input image
cv::Mat im = cv::imread("headPose.jpg"); // 2D image points. If you change the image, you need to change vector
std::vector<cv::Point2d> image_points;
image_points.push_back( cv::Point2d(, ) ); // Nose tip
image_points.push_back( cv::Point2d(, ) ); // Chin
image_points.push_back( cv::Point2d(, ) ); // Left eye left corner
image_points.push_back( cv::Point2d(, ) ); // Right eye right corner
image_points.push_back( cv::Point2d(, ) ); // Left Mouth corner
image_points.push_back( cv::Point2d(, ) ); // Right mouth corner // 3D model points.
std::vector<cv::Point3d> model_points;
model_points.push_back(cv::Point3d(0.0f, 0.0f, 0.0f)); // Nose tip
model_points.push_back(cv::Point3d(0.0f, -330.0f, -65.0f)); // Chin
model_points.push_back(cv::Point3d(-225.0f, 170.0f, -135.0f)); // Left eye left corner
model_points.push_back(cv::Point3d(225.0f, 170.0f, -135.0f)); // Right eye right corner
model_points.push_back(cv::Point3d(-150.0f, -150.0f, -125.0f)); // Left Mouth corner
model_points.push_back(cv::Point3d(150.0f, -150.0f, -125.0f)); // Right mouth corner // Camera internals
double focal_length = im.cols; // Approximate focal length.
Point2d center = cv::Point2d(im.cols/,im.rows/);
cv::Mat camera_matrix = (cv::Mat_<double>(,) << focal_length, , center.x, , focal_length, center.y, , , );
cv::Mat dist_coeffs = cv::Mat::zeros(,,cv::DataType<double>::type); // Assuming no lens distortion cout << "Camera Matrix " << endl << camera_matrix << endl ;
// Output rotation and translation
cv::Mat rotation_vector; // Rotation in axis-angle form
cv::Mat translation_vector; // Solve for pose
cv::solvePnP(model_points, image_points, camera_matrix, dist_coeffs, rotation_vector, translation_vector); // Project a 3D point (0, 0, 1000.0) onto the image plane.
// We use this to draw a line sticking out of the nose vector<Point3d> nose_end_point3D;
vector<Point2d> nose_end_point2D;
nose_end_point3D.push_back(Point3d(,,1000.0)); projectPoints(nose_end_point3D, rotation_vector, translation_vector, camera_matrix, dist_coeffs, nose_end_point2D); for(int i=; i < image_points.size(); i++)
{
circle(im, image_points[i], , Scalar(,,), -);
} cv::line(im,image_points[], nose_end_point2D[], cv::Scalar(,,), ); cout << "Rotation Vector " << endl << rotation_vector << endl;
cout << "Translation Vector" << endl << translation_vector << endl; cout << nose_end_point2D << endl; //Eigen.
cv::Mat rMatrix = cv::Mat(, , CV_64F);
cv::Rodrigues(rotation_vector, rMatrix);
Eigen::Matrix3d R;
R << rMatrix.at<double>(, ), rMatrix.at<double>(, ), rMatrix.at<double>(, ),
rMatrix.at<double>(, ), rMatrix.at<double>(, ), rMatrix.at<double>(, ),
rMatrix.at<double>(, ), rMatrix.at<double>(, ), rMatrix.at<double>(, );
Eigen::Vector3d eular_radian = R.eulerAngles(, , );//radian.
Eigen::Vector3d eular_angle = R.eulerAngles(, , )*.f/M_PI;//angle.
// Display image.
std::stringstream ss;
ss << eular_angle[];
std::string txt = "Pitch: " + ss.str();
cv::putText(im, txt, cv::Point(, ), 0.5,0.5, cv::Scalar(,,));
std::stringstream ss1;
ss1 << eular_angle[];
std::string txt1 = "Yaw: " + ss1.str();
cv::putText(im, txt1, cv::Point(, ), 0.5,0.5, cv::Scalar(,,));
std::stringstream ss2;
ss2 << eular_angle[];
std::string txt2 = "Roll: " + ss2.str();
cv::putText(im, txt2, cv::Point(, ), 0.5,0.5, cv::Scalar(,,));
cv::imshow("Output", im);
cv::waitKey(); }

参考

1. https://blog.csdn.net/ttomchy/article/details/56859841

2. https://blog.csdn.net/qq_31806429/article/details/78844305

3. https://www.learnopencv.com/head-pose-estimation-using-opencv-and-dlib/

完

【Eigen开源库】linux系统如何安装使用Eigen库的更多相关文章

  1. Linux系统下安装Gitlab

    Linux系统下安装Gitlab 一.简介 GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目.它拥有与 ...

  2. 在Linux系统下安装大于mysql5.5版本的数据库

    linux下mysql 5.5的安装方法: 1.安装所需要系统库相关库文件      gcc等开发包,在安装linux系统的时候安装. 2.创建mysql安装目录 # mkdir -p /usr/lo ...

  3. 在 Linux 系统中安装Load Generator ,并在windows 调用方法

    在 Linux 系统中安装Load Generator ,并在windows 调用 由于公司需要测试系统的最大用户承受能力,所以需要学习使用loadrunner.在安装的时候碰到了不少问题,所以写下此 ...

  4. Redis学习之一VMWare Pro虚拟机安装和Linux系统的安装

    一.引言 设计模式写完了,相当于重新学了一遍,每次学习都会有不同的感受,对设计模式的理解又加深了,理解的更加透彻了.还差一篇关于设计模式的总结的文章了,写完这篇总结性的文章,设计模式的文章就暂时要告一 ...

  5. Redis进阶实践之一VMWare Pro虚拟机安装和Linux系统的安装(转载)(1)

    Redis进阶实践之一VMWare Pro虚拟机安装和Linux系统的安装 一.引言 设计模式写完了,相当于重新学了一遍,每次学习都会有不同的感受,对设计模式的理解又加深了,理解的更加透彻了.还差一篇 ...

  6. 在Linux系统中安装caffe

    学习深度学习已经很久了,但一直没有自己动手安装过caffe,因为工作需要,需要在linux系统中安装caffe,因此,在这里对安装过程进行记录. caffe配置起来比tensorflow更麻烦一些,我 ...

  7. Redis进阶实践之一VMWare Pro虚拟机安装和Linux系统的安装

    一.引言 设计模式写完了,相当于重新学了一遍,每次学习都会有不同的感受,对设计模式的理解又加深了,理解的更加透彻了.还差一篇关于设计模式的总结的文章了,写完这篇总结性的文章,设计模式的文章就暂时要告一 ...

  8. linux linux系统的安装及使用

    linux  linux系统的安装及使用 一.linux系统中安装vm-tools工具: 步骤: 1.在vmware workstation软件中:虚拟机-安装vmware-tools-状态栏会提示- ...

  9. 2.0 Linux系统的安装之Fedora安装单系统(2)

    2.0 Linux系统的安装之Fedora安装单系统(2) *Linux系统的安装之Fedora安装单系统 恐怕最好装的系统就是Linux系统了,或者与Windows并列.此篇教程为Fedora的单系 ...

随机推荐

  1. 【LeetCode】大数相乘

    1. 模拟手工计算 原理: 将 string 反转存储在 int 数组中,如 A = 17 = (7, 1),B = 25 = (5, 2),亦即幂表示法,幂次是从低位到高位. 作逐位相乘,即 ai ...

  2. 【Python】基础知识

    一.基本概念 1.变量与运算符 Python允许给多个变量同时赋值,等号 (=) 右边的值将赋予左边对应位置的变量. # 将a, b, c的值依次赋予b, c, a b, c, a = a, b, c ...

  3. Jsop的原理

    Jsop的原理:利用script不存在跨域的问题,动态创建script标签,把需要请求的数据源地址赋值给其src属性,并且指定一个回调函数,从而接受到我们想要的数据

  4. MySql语句中Union和join的用法

    Union UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每条 SELECT ...

  5. 微信小程序FAQ

    1. 图片名注意大小写. 不然本地预览是可以看到的.上传后用手机就看不到了. 2. bindtap等事件传参 wxml <view id="tapTest" data-hi= ...

  6. Oracle 当前日期如何添加指定年数、月数、天数、时数、分钟数、秒数

    Oracle 当前时间如何添加指定数,来获取指定的年数.月份或其他的时间日期 --当前时间(2018-10-19 16:51:22)--- select sysdate nowDate from du ...

  7. shell IF分支判断语句

    单分支IF条件语句 if [ 条件判断式 ] then  程序: fi //结束的时候if反过来写 fi ----------------------------- /** * if test -d ...

  8. Win10系列:JavaScript综合实例2

    在项目中添加一个名为pages的文件夹,并在pages文件夹里面再添加一个名为mainPage的文件夹,接着在mainPage文件夹里添加一个"页面控制"项,命名为mainPage ...

  9. 【资料收集】Converting Between cv::Mat and QImage or QPixmap

    参考: 方法一 Convert between cv::Mat and QImage 两种图片类转换 - Grandyang - 博客园 http://www.cnblogs.com/grandyan ...

  10. Saiku的基本使用介绍(三)

    Saiku的基本使用介绍(这里都是使用Admin用户登录系统) 1.启动安装好的Saiku  ( ./start-saiku.sh ) ,浏览器使用访问系统 http://localhost:8080 ...