face alignment dlib

本文介绍如何使用Dlib库在图像中检测面部关键点。通过加载面部检测和姿态估计模型,检测图像中的脸部并标记出68个面部特征点。代码示例展示了从加载模型到显示结果的完整过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

face alignment dlib

  1. 代码:

  2.  
  3. void landmark(Mat face_img)

  4. {

  5. string modelfile = "C:\\WorkSpace\\SoftWare\\dlib-19.10\\models\\shape_predictor_68_face_landmarks.dat";

  6. // Load face detection and pose estimation models.

  7. frontal_face_detector detector = get_frontal_face_detector();

  8. shape_predictor pose_model;

  9. deserialize(modelfile) >> pose_model;

  10. // Detect faces

  11. cv_image<bgr_pixel> cimg(face_img);

  12.  
  13.  
  14. std::vector<dlib::rectangle> faces = detector(cimg);

  15.  
  16.  
  17. // Find the pose of each face.

  18. std::vector<full_object_detection> shapes;

  19. for (unsigned long i = 0; i < faces.size(); ++i)

  20. {

  21. shapes.push_back(pose_model(cimg, faces[i]));

  22. Rect r;

  23. r.x = faces[i].left();

  24. r.y = faces[i].top();

  25. r.width = faces[i].width();

  26. r.height = faces[i].height();

  27. cv::rectangle(face_img, r, Scalar(0, 0, 255));

  28. }

  29.  
  30.  
  31. if (!shapes.empty()) {

  32. for (int i = 0; i < 68; i++) {

  33. circle(face_img, cvPoint(shapes[0].part(i).x(), shapes[0].part(i).y()), 3, cv::Scalar(0, 0, 255), -1);

  34. // shapes[0].part(i).x();//68个

  35. }

  36. }

  37. //Display it all on the screen

  38. imshow("Dlib特征点", face_img);

  39. waitKey(0);

  40. }

 

 

效果图:

 

提示:

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.设置支持文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值