Dlib百度云下载链接:链接:https://pan.baidu.com/s/11wojOSw5iFJ5v_CriZ7SHA
提取码:dlv8
Dlib官网链接 http://dlib.net
人脸库百度云下载链接:链接:https://pan.baidu.com/s/1Thtt9x3NLWFPn3ww9JyFaA
提取码:0mz2
人脸库下载链接:http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
VS2015项目文件下载地址(只要装了VS2015下载好就可以直接运行,所需要的Dlib、人脸库都放在项目里配置好):
链接:https://pan.baidu.com/s/1ndKQJuTXFc5n0TqzwXD_Dw
提取码:lbd0
1.首先把Dlib人脸库里中dlib/all/source.cpp添加至项目
2.把下载的人脸库.dat文件添加到项目的工作目录(如果项目目录没做修改,一般和.cpp文件在同一目录,提供的本文VS2015项目文件,工作目录改为bin)。
4.mian.cpp 调用图片
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This example program shows how to find frontal human faces in an image and
estimate their pose. The pose takes the form of 68 landmarks. These are
points on the face such as the corners of the mouth, along the eyebrows, on
the eyes, and so forth.
This example is essentially just a version of the face_landmark_detection_ex.cpp
example modified to use OpenCV's VideoCapture object to read from a camera instead
of files.
Finally, note that the face detector is fastest when compiled with at least
SSE2 instructions enabled. So if you are using a PC with an Intel or AMD
chip then you should enable at least SSE2 instructions. If you are using
cmake to compile this program you can enable them by using one of the
following commands when you create the build project:
cmake path_to_dlib_root/examples -DUSE_SSE2_INSTRUCTIONS=ON
cmake path_to_dlib_root/examples -DUSE_SSE4_INSTRUCTIONS=ON
cmake path_to_dlib_root/examples -DUSE_AVX_INSTRUCTIONS=ON
This will set the appropriate compiler options for GCC, clang, Visual
Studio, or the Intel compiler. If you are using another compiler then you
need to consult your compiler's manual to determine how to enable these
instructions. Note that AVX is the fastest but requires a CPU from at least
2011. SSE4 is the next fastest and is supported by most current machines.
*/
#include
#include
#include
#include
#include
#include
using namespace dlib;
using namespace std;
#define RATIO 4
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;
// Grab and process frames until the main window is closed by the user.
// Grab a frame
cv::Mat src = cv::imread("../image/7.jpg");
cv_image cimg(src);
// 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 (unsigned long j = 0; j < faces.size(); ++j)
{
for (int i = 0; i < 68; i++)
{
//将68个特征点画到
cv::circle(src, cvPoint(shapes[j].part(i).x(), shapes[j].part(i).y()), 2, cv::Scalar(255, 0, 0), -1);
}
}
}
//Display it all on the screen
cv::imshow("Dlib特征点", src);
cv::waitKey(0);
return 0;
}
4.mian.cpp 调用摄像头
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This example program shows how to find frontal human faces in an image and
estimate their pose. The pose takes the form of 68 landmarks. These are
points on the face such as the corners of the mouth, along the eyebrows, on
the eyes, and so forth.
This example is essentially just a version of the face_landmark_detection_ex.cpp
example modified to use OpenCV's VideoCapture object to read from a camera instead
of files.
Finally, note that the face detector is fastest when compiled with at least
SSE2 instructions enabled. So if you are using a PC with an Intel or AMD
chip then you should enable at least SSE2 instructions. If you are using
cmake to compile this program you can enable them by using one of the
following commands when you create the build project:
cmake path_to_dlib_root/examples -DUSE_SSE2_INSTRUCTIONS=ON
cmake path_to_dlib_root/examples -DUSE_SSE4_INSTRUCTIONS=ON
cmake path_to_dlib_root/examples -DUSE_AVX_INSTRUCTIONS=ON
This will set the appropriate compiler options for GCC, clang, Visual
Studio, or the Intel compiler. If you are using another compiler then you
need to consult your compiler's manual to determine how to enable these
instructions. Note that AVX is the fastest but requires a CPU from at least
2011. SSE4 is the next fastest and is supported by most current machines.
*/
#include
#include
#include
#include
#include
#include
using namespace dlib;
using namespace std;
int main()
{
cv::VideoCapture cap(0);
if (!cap.isOpened())
{
cerr << "Unable to connect to camera" << endl;
return 1;
}
//image_window win;
// 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.
while (1)
{
// Grab a frame
cv::Mat src;
cap >> src;
cv_image cimg(src);
// 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++) {
//将68个特征点画到
cv::circle(src, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 2, cv::Scalar(255, 0, 0), -1);
}
}
//Display it all on the screen
imshow("Dlib特征点", src);
if (cv::waitKey(2) == 27)
break;
}
return 0;
}