前言

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

PS:这个库越来越强了,已经可以做人脸关键点检测了。关键点检测可以用于矫正人脸,再也不要用慢的要死的dlib啦~~

配置

五张图带你解决问题:(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. //define the buffer size. Do not change the size!
  6. #define DETECT_BUFFER_SIZE 0x20000
  7. int main()
  8. {
  9. int * pResults = NULL;
  10. //pBuffer is used in the detection functions.
  11. //If you call functions in multiple threads, please create one buffer for each thread!
  12. unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);
  13. if (!pBuffer)
  14. {
  15. fprintf(stderr, "Can not alloc buffer.\n");
  16. return -1;
  17. }
  18. Mat src = imread("img.jpg");
  19. Mat gray;
  20. cvtColor(src, gray, CV_BGR2GRAY);
  21. int doLandmark = 1;// do landmark detection
  22. pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step,
  23. 1.2f, 2, 48, 0, doLandmark);
  24. //print the detection results
  25. for (int i = 0; i < (pResults ? *pResults : 0); i++)
  26. {
  27. short * p = ((short*)(pResults + 1)) + 142 * i;
  28. rectangle(src, Rect(p[0], p[1], p[2], p[3]), Scalar(0, 255, 0), 2);
  29. if (doLandmark)
  30. {
  31. for (int j = 0; j < 68; j++)
  32. circle(src, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 0, 255),2);
  33. }
  34. }
  35. imshow("Show", src);
  36. waitKey(0);
  37. }

效果还是很赞:

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

  1. #include <opencv.hpp>
  2. #include <facedetect-dll.h>
  3. using namespace cv;
  4. using namespace std;
  5. //define the buffer size. Do not change the size!
  6. #define DETECT_BUFFER_SIZE 0x20000
  7. int main()
  8. {
  9. int * pResults = NULL;
  10. //pBuffer is used in the detection functions.
  11. //If you call functions in multiple threads, please create one buffer for each thread!
  12. unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);
  13. if (!pBuffer)
  14. {
  15. fprintf(stderr, "Can not alloc buffer.\n");
  16. return -1;
  17. }
  18. int doLandmark = 1;// do landmark detection
  19. VideoCapture cap(0);
  20. if (!cap.isOpened()){
  21. cout << "Please check your USB camera's interface num." << endl;
  22. return 0;
  23. }
  24. Mat src;
  25. while (true)
  26. {
  27. cap >> src;
  28. if (!src.empty()){
  29. Mat gray;
  30. cvtColor(src, gray, CV_BGR2GRAY);
  31. pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step,
  32. 1.2f, 2, 48, 0, 1);
  33. for (int i = 0; i < (pResults ? *pResults : 0); i++)
  34. {
  35. short * p = ((short*)(pResults + 1)) + 142 * i;
  36. rectangle(src, Rect(p[0], p[1], p[2], p[3]), Scalar(0, 255, 0), 2);
  37. if (doLandmark)
  38. {
  39. for (int j = 0; j < 68; j++)
  40. circle(src, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 0, 255), 2);
  41. }
  42. }
  43. imshow("Show", src);
  44. waitKey(1);
  45. }
  46. }
  47. }

如何快糙好猛的使用libfacedetection库【最新版】的更多相关文章

  1. 如何快糙好猛的使用Shiqi.Yu老师的公开人脸检测库(附源码)

    前言 本次编写所用的库为于仕祺老师免费提供的人脸检测库.真心好用,识别率和识别速度完全不是Opencv自带的程序能够比拟的.将其配合Opencv的EigenFace算法,基本上可以形成一个小型的毕业设 ...

  2. 怎样快糙猛的开始搞Kaggle比赛

  3. SAP 出库单新版

    *&---------------------------------------------------------------------* *& Report  ZSDR045 ...

  4. 人脸识别-<转>

    人脸检测库libfacedetection介绍 libfacedetection是于仕琪老师放到GitHub上的二进制库,没有源码,它的License是MIT,可以商用.目前只提供了windows 3 ...

  5. android 开发必用的开源库

    LogReport:  https://github.com/wenmingvs/LogReport,   崩溃日志上传框架 wcl-permission-demo:Android 6.0 - 动态权 ...

  6. Git学习笔记(三)远程库(GitHub)协同开发,fork和忽略特殊文件

    远程库 远程库,通俗的讲就是不再本地的git仓库!他的工作方式和我们本地的一样,但是要使用他就需要先建立连接! 远程库有两种,一个是自己搭建的git服务器:另一种就是使用GitHub,这个网站就是提供 ...

  7. c协程库libco几点体会

    https://www.cnblogs.com/dearplain/p/9820913.html 这里说的是Tencent开源的libco. libco的用途和依赖 主要还是c/c++服务端,相比li ...

  8. Dalvik模式下在Android so库文件.init段、.init_array段构造函数上下断点

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/78244766 在前面的博客<在Android so文件的.init..ini ...

  9. php大力力 [037节] Iconfont-阿里巴巴矢量图标库

    Iconfont-阿里巴巴矢量图标库 从此不求人:自主研发一套PHP前端开发框架 Iconfont-中国第一个最大且功能最全的矢量图标库,提供矢量图标下载.在线存储.格式转换等功能.阿里巴巴体验团队倾 ...

随机推荐

  1. Android学习笔记之按键操作

    我们如何和Android 程序来进行交互那份?来让 Android 程序产生相应的反应,我们不得不通过键盘事件.触摸事件.传感器事件等来实现. 键盘是Android中主要的输入设备,对按键的响应的处理 ...

  2. HTML基础第十一讲---背景标志

    转自:https://i.cnblogs.com/posts?categoryid=1121494 您是否老觉得网页「空空的」,没错!一个可能是我们还没有很多内容,另一个可能则是我们还没有设定网页背景 ...

  3. VUE笔记 - 品牌后台 - v-for Splice Some Filter findIndex indexOf 直接return函数结果

    <body> <div id="app"> <div class="panel panel-primary"> <di ...

  4. 边缘独立(marginal independent)的理解及举例

    1. 定义 ∀xi∈dom(X),yj∈dom(Y),yk∈dom(Y),如果满足, P(X=xi|Y=yj)==P(X=xi|Y=yk)P(X=Xi) 则称随机变量 X 边缘独立于随机变量 Y. 理 ...

  5. loadrunne-- Analysis 分析器

    本文转自:https://www.cnblogs.com/Chilam007/p/6445165.html Analysis简介 分析器就是对测试结果数据进行分析的组件,它是LR三大组件之一,保存着大 ...

  6. set_fix_multiple_port_nets

    set_fix_multiple_port_nets   -all    -buffer_constants 加上这个命令之后 综合之后的网表就不会出现assign语句 否则会出现

  7. [React Intl] Format Numbers with Separators and Currency Symbols using react-intl FormattedNumber

    Using a react-intl FormattedNumber component, we'll pass a Number and a few additional props in orde ...

  8. xml 标准字符过滤

    今天在代码里面看见一串非常奇怪的推断语句 if (c < 0x9 || c > 0x9 && c < 0xA || c > 0xA && c & ...

  9. mootools常用特性和示例(基础篇2)

    接着上一篇:mootools常用特性和示例(基础篇1) 1.表单操作 html: <form id="myForm" action="submit.php" ...

  10. 怎样在一个fragment or 随意类中操作还有一个fragment中的方法

    1 怎样在acitivty中运行fragment中的方法: 首先获得这个Fragment的对象 xxxFragment fragmentObject = (xxxFragment) getFragme ...