前言

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

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

配置

五张图带你解决问题:(X64,Debug)





然后你需要把opencv的属性表也引进来:

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

代码

我们直接用FDDB上评测效果最好的函数:facedetect_multiview_reinforce

#include <opencv.hpp>
#include <facedetect-dll.h>
using namespace cv;
using namespace std; //define the buffer size. Do not change the size!
#define DETECT_BUFFER_SIZE 0x20000 int main()
{
int * pResults = NULL;
//pBuffer is used in the detection functions.
//If you call functions in multiple threads, please create one buffer for each thread!
unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);
if (!pBuffer)
{
fprintf(stderr, "Can not alloc buffer.\n");
return -1;
}
Mat src = imread("img.jpg");
Mat gray;
cvtColor(src, gray, CV_BGR2GRAY);
int doLandmark = 1;// do landmark detection
pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step,
1.2f, 2, 48, 0, doLandmark);
//print the detection results
for (int i = 0; i < (pResults ? *pResults : 0); i++)
{
short * p = ((short*)(pResults + 1)) + 142 * i;
rectangle(src, Rect(p[0], p[1], p[2], p[3]), Scalar(0, 255, 0), 2);
if (doLandmark)
{
for (int j = 0; j < 68; j++)
circle(src, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 0, 255),2);
}
}
imshow("Show", src);
waitKey(0);
}

效果还是很赞:

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

#include <opencv.hpp>
#include <facedetect-dll.h>
using namespace cv;
using namespace std; //define the buffer size. Do not change the size!
#define DETECT_BUFFER_SIZE 0x20000 int main()
{
int * pResults = NULL;
//pBuffer is used in the detection functions.
//If you call functions in multiple threads, please create one buffer for each thread!
unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);
if (!pBuffer)
{
fprintf(stderr, "Can not alloc buffer.\n");
return -1;
}
int doLandmark = 1;// do landmark detection
VideoCapture cap(0);
if (!cap.isOpened()){
cout << "Please check your USB camera's interface num." << endl;
return 0;
}
Mat src;
while (true)
{
cap >> src;
if (!src.empty()){
Mat gray;
cvtColor(src, gray, CV_BGR2GRAY);
pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step,
1.2f, 2, 48, 0, 1);
for (int i = 0; i < (pResults ? *pResults : 0); i++)
{
short * p = ((short*)(pResults + 1)) + 142 * i;
rectangle(src, Rect(p[0], p[1], p[2], p[3]), Scalar(0, 255, 0), 2);
if (doLandmark)
{
for (int j = 0; j < 68; j++)
circle(src, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 0, 255), 2);
}
}
imshow("Show", src);
waitKey(1);
} }
}

最新文章

  1. Python开发【第十九篇】:Python操作MySQL
  2. volatile和const
  3. 网站整合Ucenter详细流程
  4. 获取SHA1
  5. Linux查看文件指定某些行的内容
  6. 接口管理工具——阿里RAP
  7. vim指令
  8. (17)线程队列---queue LifoQueue PriorityQueue
  9. 强化学习---TRPO/DPPO/PPO/PPO2
  10. 简单的sqlhelper的学习日志
  11. web 常用网址及资源
  12. 在winsshd 中添加id_rsa.pub 实现Windows 服务器主机自动信任Linux 客户端
  13. Navicat Premium 连接Oracle 数据库
  14. More than one file was found with OS independent path &#39;META-INF/LICENSE&#39; | Error:Could not read \build\intermediates\typedefs.txt (系统找不到指定的文件。)
  15. LDA基本介绍以及LDA源码分析(BLEI)
  16. python语法学习面向对象之继承
  17. CSP201409-1:相邻数对
  18. selenium 难定位元素,时间插件,下拉框定位,string包含,定位列表中的一个,技巧
  19. 【字符串哈希】bzoj3555 [Ctsc2014]企鹅QQ
  20. Android社会化分享功能的实现步骤

热门文章

  1. 00103_死锁、Lock接口、等待唤醒机制
  2. 00090_字节输入流InputStream
  3. UVA 294 294 - Divisors (数论)
  4. Library Component Properties的表格如何填写
  5. oled的一套stm32实验1
  6. web服务器软件(Nginx,Apache,IIS,Lighttpd)介绍
  7. 宏定义#define整理
  8. linux下设置密码复杂度限制,怎么设置?
  9. Android NetworkOnMainThreadException异常
  10. storm编程指南