Qt Dlib配置实现人脸检测

时间:2024-03-13 10:56:36

最近在用Dlib库做人脸检测,在vs2010上实践成功后,想把他移植到Qt上,毕竟用Qt做界面更漂亮。

关于windows7+vs2010+dlib-18.17的配置方法,有很多的参考资料,可以不再多说,参考:http://blog.csdn.net/taily_duan/article/details/53898214

使用最新的dlib需要使用更高版本的vs,为了能在vs2010下使用,我选择了dlib-18.17,经过测试,程序完全没有问题。

1.   Qt安装

2.  Qt配置OpenCV2.4.9

3.  CMake编译Dlib-18.17

CMake版本:CMake 3.5.2

3.1  首先打开CMake3.5.2 GUI,编译器选择MinGW

Qt Dlib配置实现人脸检测

提示Configuring done和Generating done之后,表示成功获得Makefile文件,接着就可以导出库了。

3.2  打开cmd命令,进入到刚才导出的目录,然后执行make命令,前提:确保你的电脑上由ming32-make编译器(通常Qt安装成功后就会有这个,否则CMake也不成功)。

命令如图:

Qt Dlib配置实现人脸检测

3.3   获得libdlib.a

等待一会之后,在qt_build_dlib目录下将生成libdlib.a库。

Qt Dlib配置实现人脸检测

4.配置Qt

打开Qt新建一个控制台应用程序,打开.pro,配置如下即可。

INCLUDEPATH += C:\OpenCV\OpenCV249\opencv\qt_opencv\include

INCLUDEPATH += E:\face_recognition\dlib-18.17\dlib-18.17

LIBS += C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_imgproc249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_calib3d249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_contrib249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_core249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_features2d249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_flann249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_gpu249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_highgui249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_legacy249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_ml249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_nonfree249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_objdetect249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_ocl249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_photo249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_stitching249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_superres249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_video249.dll.a\
        C:\OpenCV\OpenCV249\opencv\qt_opencv\lib\libopencv_videostab249.dll.a\
        C:\OpenCV\libdlib.a

Qt Dlib配置实现人脸检测

5.  测试程序效果

Qt Dlib配置实现人脸检测


6.  结论

检测的结果比opencv自带的检测器准确多了,但是实时性却不太高,这里有待进一步的改进。