概述
最近在学习人脸识别,比如Dlib,face++,于仕琪人脸检测算法以及opencv自带的人脸识别算法。
对于于仕琪人脸检测算法网上的配置不是很详细,再次记录一下配置过程。
下载地址:于仕琪人脸检测算法:https://github.com/ShiqiYu/libfacedetection
1:解压
2:创建一个空工程
3:配置
点击工程,右击选择属性
(1)点击VC++目录
在包含目录选择 libfacedetection-masterlibfacedetection-masterinclude 目录
在库目录选择 libfacedetection-masterlibfacedetection-masterlib 目录
(2)点击链接器
在输入添加:libfacedetect.lib libfacedetect-x64.lib
4:将 libfacedetection-masterlibfacedetection-masterbin中的libfacedetect.dll与libfacedetect-x64.dll复制到C:WindowsSysWOW64中(64位),32位复制到C:WindowsSystem32中。
新建
cpp
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "facedetect-dll.h"
//#pragma comment(lib,"libfacedetect.lib")
#pragma comment(lib,"libfacedetect-x64.lib")
//define the buffer size. Do not change the size!
#define DETECT_BUFFER_SIZE 0x20000
using namespace cv;
int main(int argc, char* argv[])
{
argc = 2;
if(argc != 2)
{
printf("Usage: %s <image_file_name>n", argv[0]);
return -1;
}
//load an image and convert it to gray (single-channel)
Mat image = imread(argv[1]);//图片目录
if(image.empty())
{
fprintf(stderr, "Can not load the image file %s.n", argv[1]);
return -1;
}
Mat gray;
cvtColor(image, gray, CV_BGR2GRAY);
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;
///
// frontal face detection / 68 landmark detection
// it's fast, but cannot detect side view faces
//
//!!! The input image must be a gray one (single-channel)
//!!! DO NOT RELEASE pResults !!!
pResults = facedetect_frontal(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_frontal = image.clone();
//print the detection results
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=%dn", x, y, w, h, neighbors, angle);
rectangle(result_frontal, Rect(x, y, w, h), Scalar(0, 255, 0), 2);
if (doLandmark)
{
for (int j = 0; j < 68; j++)
circle(result_frontal, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 255, 0));
}
}
imshow("Results_frontal", result_frontal);
///
// frontal face detection designed for video surveillance / 68 landmark detection
// it can detect faces with bad illumination.
//
//!!! The input image must be a gray one (single-channel)
//!!! DO NOT RELEASE pResults !!!
pResults = facedetect_frontal_surveillance(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_frontal_surveillance = image.clone();;
//print the detection results
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=%dn", x, y, w, h, neighbors, angle);
rectangle(result_frontal_surveillance, Rect(x, y, w, h), Scalar(0, 255, 0), 2);
if (doLandmark)
{
for (int j = 0; j < 68; j++)
circle(result_frontal_surveillance, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 255, 0));
}
}
imshow("Results_frontal_surveillance", result_frontal_surveillance);
///
// multiview face detection / 68 landmark detection
// it can detect side view faces, but slower than facedetect_frontal().
//
//!!! The input image must be a gray one (single-channel)
//!!! DO NOT RELEASE pResults !!!
pResults = facedetect_multiview(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();;
//print the detection results
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=%dn", x, y, w, h, neighbors, angle);
rectangle(result_multiview, Rect(x, y, w, h), Scalar(0, 255, 0), 2);
if (doLandmark)
{
for (int j = 0; j < 68; j++)
circle(result_multiview, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 255, 0));
}
}
imshow("Results_multiview", result_multiview);
///
// reinforced multiview face detection / 68 landmark detection
// it can detect side view faces, better but slower than facedetect_multiview().
//
//!!! The input image must be a gray one (single-channel)
//!!! DO NOT RELEASE pResults !!!
pResults = facedetect_multiview_reinforce(pBuffer, (unsigned char*)(gray.ptr(0)), gray.cols, gray.rows, (int)gray.step,
1.2f, 3, 48, 0, doLandmark);
printf("%d faces detected.n", (pResults ? *pResults : 0));
Mat result_multiview_reinforce = image.clone();;
//print the detection results
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=%dn", x,y,w,h,neighbors, angle);
rectangle(result_multiview_reinforce, Rect(x, y, w, h), Scalar(0, 255, 0), 2);
if (doLandmark)
{
for (int j = 0; j < 68; j++)
circle(result_multiview_reinforce, Point((int)p[6 + 2 * j], (int)p[6 + 2 * j + 1]), 1, Scalar(0, 255, 0));
}
}
imshow("Results_multiview_reinforce", result_multiview_reinforce);
waitKey();
//release the buffer
free(pBuffer);
return 0;
}
或者导入 libfacedetection-masterlibfacedetection-masterexample中的libfacedetect-example.cpp
直接debug编译即可
最后
以上就是机灵泥猴桃为你收集整理的vs2013+opencv3.2配置于仕琪人脸检测算法的全部内容,希望文章能够帮你解决vs2013+opencv3.2配置于仕琪人脸检测算法所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复