当我们使用到dlib的dnn做人脸识别时,使用vs2015编译代码的效率太低,每次重新编译都会花费很长的时间,且对于使用MFC设计UI无感,因此将使用QT5.8使用dlib-19.4和OpenCV2.4.9,记录下使用CMake编译库的命令。
1.使用Qt5.8的MingW-32编译器
g++的版本是5.3.0,支持c++11语法(这点需要注意,老版本可能不支持c++11,导致编译失败)。
2.mingw32编译dlib-19.4
2.1 CMake命令:
使用的CMake版本是:CMake3.9.0
2.2 Make命令
2.3 qt使用dlib-19.4的配置
QT += core
QT -= gui
CONFIG += c++11
TARGET = opencv_dlib_qt
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp \
DNNFaceRecognition.cpp \
cfaceclassthread.cpp
# The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH += E:\face_recognition\dlib-19.4\dlib-19.4
LIBS += C:\dlib_19_4\libdlib.a
QMAKE_CXXFLAGS += -std=c++11 -DDLIB_PNG_SUPPORT -DDLIB_JPEG_SUPPORT
QMAKE_CFLAGS_DEBUG = -O2 -Os -MD
INCLUDEPATH += C:\OpenCV\opencv_qt\include
LIBS += C:\OpenCV\opencv_qt\lib\libopencv_imgproc249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_calib3d249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_contrib249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_core249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_features2d249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_flann249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_gpu249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_highgui249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_legacy249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_ml249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_nonfree249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_objdetect249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_ocl249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_photo249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_stitching249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_superres249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_video249.dll.a\
C:\OpenCV\opencv_qt\lib\libopencv_videostab249.dll.a
3.Qt5.8 mingw32编译OpenCV2.4.9
3.1 CMake命令
cmake -DCMAKE_INSTALL_PREFIX=C:/OpenCV/opencv_qt -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Release -G"MinGW Makefiles" ..
cmake -DCMAKE_INSTALL_PREFIX=C:/opencv249/opencv-2.4.9/build -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Release -G"MinGW Makefiles" ..
3.2 Make命令
mingw32-make -f Makefile
参考文献