人脸特征点检测-于老师算法

最近已经很少看CSDN了。这一年多准备考研,基本上怕是不会再怎么上了。以前有一个http://blog.csdn.net/mr_curry/article/details/51804072 如何快糙好猛的使用Shiqi.Yu老师的公开人脸检测库(附源码)的BLOG,因为于老师的库已经更新了,所以重新写一下吧。 
PS:这个库越来越强了,已经可以做人脸关键点检测了。关键点检测可以用于矫正人脸,再也不要用慢的要死的dlib啦~~

转载地址::http://blog.csdn.net/mr_curry/article/details/65945071

配置

五张图带你解决问题:(X64,Debug) 
这里写图片描述
这里写图片描述
这里写图片描述

然后你需要把opencv的属性表也引进来: 
这里写图片描述

两个方法,加系统变量或者放到和exe同一个文件夹下。加了系统变量后重启一次才生效,所以这里就直接放咯 
这里写图片描述

代码

我们直接用FDDB上评测效果最好的函数:facedetect_multiview_reinforce 
这里写图片描述

 
  1. #include <opencv.hpp>

  2. #include <facedetect-dll.h>

  3. using namespace cv;

  4. using namespace std;

  5.  
  6. //define the buffer size. Do not change the size!

  7. #define DETECT_BUFFER_SIZE 0x20000

  8.  
  9. int main()

  10. {

  11. int * pResults = NULL;

  12. //pBuffer is used in the detection functions.

  13. //If you call functions in multiple threads, please create one buffer for each thread!

  14. unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);

  15. if (!pBuffer)

  16. {

  17. fprintf(stderr, "Can not alloc buffer.\n");

  18. return -1;

  19. }

  20. Mat src = imread("img.jpg");

  21. Mat gray;

  22. cvtColor(src, gray, CV_BGR2GRAY);

  23. int doLandmark = 1;// do landmark detection

  24. pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step,

  25. 1.2f, 2, 48, 0, doLandmark);

  26. //print the detection results

  27. for (int i = 0; i < (pResults ? *pResults : 0); i++)

  28. {

  29. short * p = ((short*)(pResults + 1)) + 142 * i;

  30. rectangle(src, Rect(p[0], p[1], p[2], p[3]), Scalar(0, 255, 0), 2);

  31. if (doLandmark)

  32. {

  33. for (int j = 0; j < 68; j++)

  34. circle(src, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 0, 255),2);

  35. }

  36. }

  37. imshow("Show", src);

  38. waitKey(0);

  39. }

效果还是很赞: 
这里写图片描述

视频流中的人脸检测代码就是用VideoCapture解析为Mat然后循环检测啊:

 
  1. #include <opencv.hpp>

  2. #include <facedetect-dll.h>

  3. using namespace cv;

  4. using namespace std;

  5.  
  6. //define the buffer size. Do not change the size!

  7. #define DETECT_BUFFER_SIZE 0x20000

  8.  
  9. int main()

  10. {

  11. int * pResults = NULL;

  12. //pBuffer is used in the detection functions.

  13. //If you call functions in multiple threads, please create one buffer for each thread!

  14. unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);

  15. if (!pBuffer)

  16. {

  17. fprintf(stderr, "Can not alloc buffer.\n");

  18. return -1;

  19. }

  20. int doLandmark = 1;// do landmark detection

  21. VideoCapture cap(0);

  22. if (!cap.isOpened()){

  23. cout << "Please check your USB camera's interface num." << endl;

  24. return 0;

  25. }

  26. Mat src;

  27. while (true)

  28. {

  29. cap >> src;

  30. if (!src.empty()){

  31. Mat gray;

  32. cvtColor(src, gray, CV_BGR2GRAY);

  33. pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step,

  34. 1.2f, 2, 48, 0, 1);

  35. for (int i = 0; i < (pResults ? *pResults : 0); i++)

  36. {

  37. short * p = ((short*)(pResults + 1)) + 142 * i;

  38. rectangle(src, Rect(p[0], p[1], p[2], p[3]), Scalar(0, 255, 0), 2);

  39. if (doLandmark)

  40. {

  41. for (int j = 0; j < 68; j++)

  42. circle(src, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 0, 255), 2);

  43. }

  44. }

  45. imshow("Show", src);

  46. waitKey(1);

  47. }

  48.  
  49. }

  50. }

猜你喜欢

转载自blog.csdn.net/pingfan2014/article/details/81153083