您的位置:首页 > 其它

【dlib】人脸68特征点检测

2017-07-04 17:00 344 查看
有部分转自:http://blog.csdn.net/zmdsjtu/article/details/53454071

VS2012 dlib库:http://download.csdn.net/detail/qq_15947787/9885919

源码如下:http://download.csdn.net/detail/qq_15947787/9888611(包含shape_predictor_68_face_landmarks.dat)

运行时x64 Release速度可以接受,Debug下检测速度很慢很慢

#include <dlib/opencv.h>
#include <opencv2/opencv.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;
using namespace std;

int main()
{
try
{
// 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;

// Grab and process frames until the main window is closed by the user.

// Grab a frame
cv::Mat temp;
//cap >> temp;
temp = cv::imread("1.jpg", 1);

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 j = 0; j < shapes.size(); j++)
{
for (int i = 0; i < 68; i++)
{
circle(temp, cvPoint(shapes[j].part(i).x(), shapes[j].part(i).y()), 3, cv::Scalar(0, 0, 255), -1);
putText(temp, to_string(i), cvPoint(shapes[j].part(i).x(), shapes[j].part(i).y()), CV_FONT_HERSHEY_PLAIN, 1, cv::Scalar(255, 0, 0),1,4);
}
}
}

//Display it all on the screen
imshow("Dlib特征点", temp);
imwrite("Dlib特征点.jpg", temp);

cv::waitKey(0);
}
catch (serialization_error& e)
{
cout << "You need dlib's default face landmarking model file to run this example." << endl;
cout << "You can get it from the following URL: " << endl;
cout << "   http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2" << endl;
cout << endl << e.what() << endl;
}
}





将dlib人脸68特征点检测与caffe结合,能做出很好玩的程序,附上大神的:

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