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

一、效果图

参照

 

二、开发环境

(1)windows 10; 

(2)Qt 5.8;

(3)opencv3.2;

(4)dlib 19.7;

(5)C++ 

 

三、代码

 

//
#include <iostream>
#include <dlib/opencv.h>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>

#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>

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<bgr_pixel> cimg(temp);
        // Detect faces
        std::vector<rectangle> faces = detector(cimg);
        // Find the pose of each face.
        std::vector<full_object_detection> 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);
    }

}
//

 

 

 

 

 


 

展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读