基于Dlib和OpenCV的人脸姿态估计(HeadPoseEstimation)

1.简介

人脸姿态估计主要是获得脸部朝向的角度信息。本文获得的人脸姿态信息用三个欧拉角(pitch,yaw,roll)表示。
首先定义一个6关键点的3D脸部模型(左眼角,右眼角,鼻尖,左嘴角,右嘴角,下颌),然后采用Dlib检测出图片中对应的6个脸部关键点,采用OpenCV的solvePnP函数解出旋转向量,最后将旋转向量转换为欧拉角。
Pose估计结果

2.定义6关键点的3D Model

3D Model

    // 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

3.基于Dlib的人脸关键点检测

Dlib提供了一个68关键点的检测模型,而且是按照顺序排列的。因此可以直接索引到需要的6个关键点。

3.1 Dlib的使用

首先前往Dlib官网下载源码并解压。有多种编译方式,这里介绍比较简单的在VS2015的编译方式。
首先把dlib/all/source.cpp添加到工程里,然后把Dlib的路径添加到工程属性表的include里。具体参见Dlib的how to compile页面。

Compiling on Windows Using Visual Studio 2015 or Newer

All you need to do is create an empty console project. Then add dlib/all/source.cpp to it and add the folder containing the dlib folder to the #include search path. Then you can compile any example program by adding it to your project.

Again, note that dlib will only be able to work with jpeg and png files if you link in libjpeg and libpng. In Visual Studio, the easiest way to do this is to add all the libjpeg, libpng, and zlib source files in the dlib/external folder into your project and also define the DLIB_PNG_SUPPORT and DLIB_JPEG_SUPPORT preprocessor directives. If you don’t know how to configure Visual Studio then you should use CMake as shown above since it will take care of everything automatically.

<
  • 13
    点赞
  • 113
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值