OpenCV学习笔记(11):libfacedetection人脸检测的配置与使用
来源:互联网 发布:恶意软件博物馆 编辑:程序博客网 时间:2024/06/11 16:46
1. 前言
libfacedetection库是深圳大学的于仕琪老师发布的开源人脸检测库,相比于OpenCV自带的CascadeClassifier人脸检测,无论在速度上还是精度上,都有巨大的优势,是目前已知开源库中最好用的一款。
本文通过学习libfacedetection库中的example,进行人脸检测程序的简单实现。
2. 开发环境
- OpenCV3.3
- Windows 10 64位
- Visual Studio 2013 Ultimate
3. 配置过程
3.1 libfacedetection的下载
在GitHub上下载libfacedetection的最新库文件(https://github.com/ShiqiYu/libfacedetection)
3.2 新建VS工程
将下载好的libfacedetection文件夹中的几个文件拖拽到faceDetection工程的根目录,包括——
- libfacedetect-x64.dll
- libfacedetect-x64.lib
- facedetect-dll.h
3.3 配置VS属性
先配置opencv
然后在链接器中配置libfacedetection的库文件,注意,64位的要配置成libfacedetect-x64.lib
注意,libfacedetection库中使用了比较底层的fopen函数,VS2013对fopen报编译错误,需要设置如下——
在C++命令行中添加 /D _CRT_SECURE_NO_WARNINGS
4. 源代码示例
这是对libfacedetection文件中example进行的修改使用,example提供了4个人脸检测函数,分别是facedetect_frontal、facedetect_frontal_surveillance、facedetect_multiview、facedetect_multiview_reinforce,四个函数应该是对应不同的使用场景,性能有所不同,但参数类型完全一致,可以根据需要进行调整。
该代码使用了 facedetect_multiview 和 OpenCV自带的CascadeClassifier进行比较,可以看出于仕琪老师的libfacedetection具有更强的性能。
#include"facedetect-dll.h"#include<iostream>#include<opencv2\opencv.hpp>#define DETECT_BUFFER_SIZE 0x20000using namespace std;using namespace cv;void faceDetection(const Mat&image){ Mat gray; cvtColor(image, gray, CV_BGR2GRAY); int * pResults = NULL; unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE); int doLandmark = 1; pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step, 1.2f, 2, 48, 0, doLandmark); printf("%d faces detected.\n", (pResults ? *pResults : 0)); Mat result_multiview = image.clone();; for (int i = 0; i < (pResults ? *pResults : 0); i++) { short * p = ((short*)(pResults + 1)) + 142 * i; int x = p[0]; int y = p[1]; int w = p[2]; int h = p[3]; int neighbors = p[4]; int angle = p[5]; printf("face_rect=[%d, %d, %d, %d], neighbors=%d, angle=%d\n", x, y, w, h, neighbors, angle); rectangle(result_multiview, Rect(x, y, w, h), Scalar(0, 255, 0), 2); } imshow("face", result_multiview); waitKey(0); free(pResults);}int main(){ Mat src = imread("test.png", IMREAD_COLOR); faceDetection(src); CascadeClassifier ccf; vector<Rect> faceBox; ccf.load("haarcascade_frontalface_default.xml"); ccf.detectMultiScale(src, faceBox, 1.1,3, 0, Size(20, 20), Size(100, 100)); for (vector<Rect>::const_iterator i = faceBox.begin(); i != faceBox.end(); i++) { rectangle(src, (*i), Scalar(0, 0, 255), 2); } imshow("cascade", src); waitKey(0); return 0;}
5. 结果对比
libfacedetection识别Tara女团结果
OpenCV CascadeClassifier 识别Tara
- OpenCV学习笔记(11):libfacedetection人脸检测的配置与使用
- 人脸检测--libfacedetection
- 【OpenCV】于仕祺老师免费提供的人脸检测库libfacedetection
- 人脸检测库libfacedetection介绍
- Opencv+Qt+libfacedetection【人脸识别&人脸挂件】
- OpenCV学习笔记:基于Haar特征的人脸检测
- OpenCV学习笔记(四):OpenCV SIFT特征的检测与匹配 测试
- OpenCV学习笔记:人脸检测(级联分类器)
- OpenCV学习笔记(10):人脸检测
- OpenCV学习笔记(三)人脸检测的代码分析(1)
- OpenCV学习笔记(三)人脸检测的代码分析
- OpenCV学习笔记(三)人脸检测的代码分析
- OpenCV学习笔记(三)人脸检测的代码分析
- OpenCV学习笔记(三)人脸检测的代码分析(2)
- OpenCV学习笔记(三)人脸检测的代码分析
- 【OpenCV 学习笔记】1、OpenCV的下载与配置
- OpenCV学习笔记(0x00) OpenCV的安装与配置
- 【OpenCV学习笔记】3:OpenCV自带的Haar特征人脸检测
- visual studio 2017出现MSB8020,MSB8036等SDK版本选择的错误
- 9种高性能可用高并发的技术架构
- [Linux] Tomcat7+MySQL5+nginx+CentOS6
- freemaker创建word文档
- 学习总结8
- OpenCV学习笔记(11):libfacedetection人脸检测的配置与使用
- php最全的正则表达式手册
- jQuery 国家语言(Language)选择切换的示例。
- PHP正则表达式匹配自定义开头结尾之前字符串
- HDU4039 The Social Network(bfs)
- 正则表达式的运用
- POI
- 删除购物车数据
- 如何给boostrap模态框传值