Libfacedetection是由作者ShiqiYu发布在Github上的遵循MIT开源协议的公共库。Libfacedetection是一个用于图像中人脸检测和人脸标识(Landmark)检测的二进制库,提供了windows下与arm版本 32位和64位的动态库文件。为了达到最好的性能,建议使用64位的DLL动态库。
下载地址:https://codeload.github.com/ShiqiYu/libfacedetection/zip/master
本文仅介绍API的使用,稍后几篇文章会给出性能测试数据及自己改的demo(可播放文件及实时流)
头文件:facedetect-dll.h


可以看到四个API的参数是一致的,下面介绍下函数含义:
/*
unsigned char * result_buffer // 缓冲区,大小必须为0x20000个字节。buffer memory for storing face detection results, !!its size must be 0x20000 Bytes!!
unsigned char * gray_image_data // 单通道灰色图像(YUV数据中的Y)
int width // 单通道灰色图像的宽度
int height // 单通道灰色图像的高度
int step // 单通道灰色图像的step参数,同单通道灰色图像的宽度,input image, it must be gray (single-channel) image!
float scale // 每次缩小图像的比例,不建议修改(default: 1.2f),scale factor for scan windows
int min_neighbors // 检测出的人脸框属性,越大表示是人脸可能性越大.小于min_neighbors的人脸框将被过滤掉。
// how many neighbors each candidate rectangle should have to retain it
int min_object_width // 数据源中近乎最小的人脸大小,若存在人脸大小比此数据还小的人脸则忽略不检测.
// Minimum possible face size. Faces smaller than that are ignored.
int max_object_width = 0 // 数据源中近乎最大的人脸大小,若存在人脸大小比此数据还大的则忽略不检测.若此数据被指定为0, 程序会自动确认可能的最大的人脸大小.
// Maximum possible face size.Faces larger than that are ignored.It is the largest posible when max_object_width = 0.
int doLandmark = 0 // 是否进行人脸特征点检测 0: 不进行人脸特征点检测1: 进行人脸特征点检测 landmark detection
*/
下面介绍一下四个API的不同:
/*
正面人脸检测,无法检测“侧视人脸”和“单面人脸”
int * facedetect_frontal(…)
正面视频监控人脸检测,无法检测“侧视人脸”和“单面人脸”,可以检测光线不好情况下的人脸
int *facedetect_frontal_surveillance(…)
多视图人脸检测,无法检测“单面人脸”,但可以检测“侧视人脸”,可以检测多张人脸,比facedetect_frontal()检测时间长
int *facedetect_multiview(…)
多视图增强人脸检测,无法检测“单面人脸”,但可以检测“侧视人脸”, 可以检测多张人脸;比facedetect_multiview()效果好,但是检测时间长
int *facedetect_multiview_reinforce(…)
*/
返回值介绍:
比如返回值为int *pResults;
pResults为空代表检测失败。如果pResults不为空,*pResults为0,代表检测成功但未检测到人脸;如果pResults不为空,*pResults不为0,*pResults代表检测到的人脸个数。
具体人脸属性参数请看下面代码:
if (NULL == pResults)
{
//printf("---Detect Failed !\n");
}
else
{
if (0 == (*pResults))
{ //No Face
//printf("---Detect success, but no face here.\n");
}
else
{
//Got Face,
//得到每个人脸的位置及宽度高度,眼睛关注角度(左正右负,正脸角度为0),置信度(越大人脸的可能性越大)
for (int i = 0; i < (pResults ? *pResults : 0); i++)
{
short * p = ((short*)(pResults + 1)) + 142 * i;
FaceFrame stFaceFrame;
//得到人脸的位置及宽度高度
stFaceFrame.x = p[0];
stFaceFrame.y = p[1];
stFaceFrame.width = p[2];
stFaceFrame.height = p[3];
//置信度(越大人脸的可能性越大)
stFaceFrame.neighbors = p[4];
//眼睛关注角度(左正右负,正脸角度为0)
stFaceFrame.angle = p[5];
// 得到人脸的特征点
for (int j = 0; j < 68; j++)
{
//printf("FaceID : %d, Point No : %d, x = %d, y = %d\n", i, j,
//(int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]);
}
}
}
}
Libfacedetection是一个开源的人脸检测库,提供多种API用于不同场景的人脸检测,包括正面人脸、多视图人脸等,并支持人脸特征点检测。该库包含Windows和ARM平台的动态链接库。
8490

被折叠的 条评论
为什么被折叠?



