使用c++版dlib做人脸对齐

素颜马尾好姑娘i 2023-01-21 10:15 24阅读 0赞

dlib提供好了一个做人脸对齐的方法get_face_chip_details

人脸对齐的原理也很简单,主要是先通过人脸关键点检测,然后对其进行仿射变换,得到标准人脸。

使用例子如下:

  1. #include"dlib/image_processing/frontal_face_detector.h"
  2. #include"dlib/image_processing/render_face_detections.h"
  3. #include "dlib/image_processing.h"
  4. #include"dlib/image_io.h"
  5. #include"dlib/gui_widgets.h"
  6. #include"dlib/opencv/cv_image.h"
  7. #include"dlib/opencv.h"
  8. #include<opencv2/imgproc.hpp>
  9. #include<opencv2/objdetect/objdetect.hpp>
  10. #include<opencv2/core/core.hpp>
  11. #include<opencv2/highgui/highgui.hpp>
  12. #include<opencv2/opencv.hpp>
  13. #include<opencv2/imgproc/imgproc.hpp>
  14. #include<iostream>
  15. using namespace std;
  16. using namespace dlib;
  17. using namespace cv;
  18. int main() {
  19. frontal_face_detector detector = get_frontal_face_detector();
  20. array2d<rgb_pixel> cimg;
  21. load_image(cimg,"1.jpg");
  22. Mat image = imread("1.jpg");
  23. shape_predictor sp;
  24. deserialize("shape_predictor_68_face_landmarks.dat") >> sp;
  25. std::vector<dlib::rectangle> face_DLib = detector(cimg);
  26. if (face_DLib.empty()) {
  27. cout << "No face is deteced by DLib" << endl;
  28. }
  29. full_object_detection shape = sp(dlib::cv_image<unsigned char>(image), face_DLib[0]);
  30. matrix<rgb_pixel> face_chip;
  31. extract_image_chip(cimg, dlib::get_face_chip_details(shape, 256, 0.25), face_chip);
  32. return 0;
  33. }

最终得到的face_chip就是我们需要的对齐后的结果。

发表评论

表情:
评论列表 (有 0 条评论,24人围观)

还没有评论,来说两句吧...

相关阅读

    相关 mtcnn 人脸对齐

     很多自拍脸并不是正的,特别是很多妹子自拍歪着头的, 但是很多任务需要的图需要不是歪着头 这个时候就需要转换 首先需要去下载工具: git clone http

    相关 人脸关键点提取(dlib)

    作者使用开发环境Ubuntu16.04+Python3 摘要 人脸关键点识别在机器视觉领域已经发展的相当成熟。比如商汤科技人脸关键点定位 毫秒级别眼、口、鼻轮廓等人