您的位置:首页 > 运维架构

毫秒级opencv的人脸特征点的检测

2017-12-27 15:03 323 查看
这里用到了大名鼎鼎于仕琪老师的开源库,下面附上于老师的项目下载链接
https://github.com/ShiqiYu/libfacedetection
然后就是环境的配置,具体见链接

http://blog.csdn.net/mono_1032290547/article/details/78912548

#include <opencv.hpp>
#include <facedetect-dll.h>
using namespace cv;
using namespace std;

//定义缓冲区大小。不要改变尺寸!
#define DETECT_BUFFER_SIZE 0x20000

int main()
{
int * pResults = NULL;
//在检测函数中使用了pBuffer。
//如果你调用多个线程中的函数,请为每个线程创建一个缓冲区!
unsigned char * pBuffer = (unsigned char *)malloc(DETECT_BUFFER_SIZE);
if (!pBuffer)
{
fprintf(stderr, "Can not alloc buffer.\n");
return -1;
}
Mat src = imread("keliamoniz1.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);
//打印检测结果
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);
}


毫秒级,速度比借助dlib快非常多

效果图
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: