最近在捣鼓人脸对齐,看见公司的同事都是用的dlib,所以也寻思着用一下,下面记载了我的整个配置流程:
step1 下载Dlib-19.2:http://dlib.net/compile.html
step2 解压:(我的路径:D:\FuXueping\DLib)
step3 安装VS2015.(注:百度经验上找的安装方法:http://jingyan.baidu.com/article/642c9d34fc5fa0644b46f74a.html)
step4 环境变量配置:我的电脑——>右键——>属性——>高级系统设置——>环境变量——>path,继续操作如下图:
step5 打开vs2015新建一个工程,进行如下配置(用图片说明):
step 6 把dlib\external\libjpeg;dlib\external\libpng;dlib\external\zlib加载到资源文件中
我的人脸检测代码是:
#include<dlib/image_processing/frontal_face_detector.h>
#include<dlib\image_processing\render_face_detections.h>
#include<dlib\image_processing.h>
#include<dlib\gui_widgets.h>
#include<dlib\image_io.h>
#include<iostream>
#include<vector>
//#define DDLIB_JPEG_SUPPORT
//#define DLIB_PNG_SUPPORT
using namespace dlib;
using namespace std;
int main(int argc, char **argv)
{
try
{
frontal_face_detector detector = get_frontal_face_detector();
image_window win;//一个显示窗口
array2d<unsigned char> img;
cout << "processing image" << argv[1] << endl;
load_image(img,argv[1]);//加载一张图片
pyramid_up(img);//对图像进行上采样,检测更小的人脸
//开始检测,返回一系列的边界框
std::vector<rectangle> dets = detector(img);//detector()函数检测人脸,返回一系列边界盒子
cout << "Number of faces detected:" << dets.size() << endl;//re
//在原图上显示结果
win.clear_overlay();
win.set_image(img);
win.add_overlay(dets, rgb_pixel(255, 0, 0));
cout << "Hit enter to process the next image..." << endl;
cin.get();
}
catch (const std::exception& e)
{
cout << "\nexception thrown!" << endl;
cout << e.what() << endl;
}
getchar();
}
运行的效果图:
总结:这次配置主要是问题就是图片读不出来,晚上折腾了三四个钟,早上才做出来,但人脸检测的速度真的好慢,希望人脸对齐的速度会好很多!
参考:http://blog.csdn.net/shuzfan/article/details/52149882
第一次用,配置当中可能有一些重复工作,希望错误的地方可以帮我指出。谢谢