人脸检测 libfacedetection-cnn win10-vs2017实现
1 代码下载
于仕琪老师的公开代码地址
链接: link.
2 建立新的控制台程序
3 添加现有项
将下载的代码解压缩,在src中的四个(如图)复制到工程中libfacedetect文件夹下,并添加至工程。
在工程中新建 .cpp ,然后将example中的detect-image.cpp(修改如下)复制到新建cpp文件
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "facedetectcnn.h"
//define the buffer size. Do not change the size!
#define DETECT_BUFFER_SIZE 0x20000
using namespace cv;
int main()
{
string str = "H:/人脸识别/DataSets/AR-full-bmp/man/002/22.bmp";
Mat image = imread(str);
if(!image.empty())
{
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;
}
///
// CNN face detection
// Best detection rate
//
//!!! The input image must be a BGR one (three-channel) instead of RGB
//!!! DO NOT RELEASE pResults !!!
TickMeter cvtm;
cvtm.start();
pResults = facedetect_cnn(pBuffer, (unsigned ch