face alignment dlib
-
代码:
-
void landmark(Mat face_img)
-
{
-
string modelfile = "C:\\WorkSpace\\SoftWare\\dlib-19.10\\models\\shape_predictor_68_face_landmarks.dat";
-
// Load face detection and pose estimation models.
-
frontal_face_detector detector = get_frontal_face_detector();
-
shape_predictor pose_model;
-
deserialize(modelfile) >> pose_model;
-
// Detect faces
-
cv_image<bgr_pixel> cimg(face_img);
-
std::vector<dlib::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]));
-
Rect r;
-
r.x = faces[i].left();
-
r.y = faces[i].top();
-
r.width = faces[i].width();
-
r.height = faces[i].height();
-
cv::rectangle(face_img, r, Scalar(0, 0, 255));
-
}
-
if (!shapes.empty()) {
-
for (int i = 0; i < 68; i++) {
-
circle(face_img, 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
-
imshow("Dlib特征点", face_img);
-
waitKey(0);
-
}
效果图:
提示:
1.严重性 代码 说明 项目 文件 行 禁止显示状态
错误 LNK2001 无法解析的外部符号 USER_ERROR__inconsistent_build_configuration__see_dlib_faq_2 cv_example C:\WorkSpace\Visual_studio\c_design\c_practice\cv_example\main.obj 1
如果出现这种 错误 请将 dlib\all\source.cpp 添加到工程目录下。
环境配置:
1. include 包含目录
2.库文件 dlib.lib 目录
3.设置 输入 需要的库文件
4.设置支持文件