您的位置:首页 > 运维架构

4、dlib学习笔记--提取人脸特征点(68点,opencv画图)

2018-01-26 15:00 1801 查看
一、效果图



参照



二、开发环境

(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);
}

}
//
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: