dlib--提取人脸特征点(68点,opencv画图)

一、效果图

dlib--提取人脸特征点(68点,opencv画图)_第1张图片

参照

dlib--提取人脸特征点(68点,opencv画图)_第2张图片

 

二、开发环境

(1)windows 10; 

(2)Qt 5.8;

(3)opencv3.2;

(4)dlib 19.7;

(5)C++ 

 

三、代码

 

//
#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 

using namespace dlib;

int main()
{
    // Load face detection and pose estimation models.
    frontal_face_detector detector = get_frontal_face_detector();
    shape_predictor pose_model;
    deserialize("shape_predictor_68_face_landmarks.dat") >> pose_model;

    while(1)
    {
        cv::VideoCapture cap("wse.jpeg");
        if (!cap.isOpened())
        {
            std::cout << "Unable to connect to camera" << std::endl;
            return 1;
        }
        cv::Mat temp;

        cap >> temp;
        cv_image cimg(temp);
        // Detect faces
        std::vector faces = detector(cimg);
        // Find the pose of each face.
        std::vector shapes;
        for (unsigned long i = 0; i < faces.size(); ++i)
           shapes.push_back(pose_model(cimg, faces[i]));

        if (!shapes.empty()) {
           for (int i = 0; i < 68; i++) {
               circle(temp, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 3, cv::Scalar(0, 0, 255), -1);
               //  shapes[0].part(i).x();//68个
           }
        }
        //Display it all on the screen
        cv::imshow("", temp);
        cv::waitKey(33);
    }

}
//

 

 

 

 

 


 

你可能感兴趣的:(Qt,Dlib)