尝试使用Dlib进行人脸检测
环境Windows10 64bit python3.6
Install Visual Studio 2015
https://my.visualstudio.com/Downloads?q=visual%20studio%202015&wt.mc_id=o~msft~vscom~older-downloads
Install CMake latest
https://cmake.org/download/
/不建议在已经安装python的情况下安装Anaconda///
Install Anaconda(python 3.6) latest
设置Anaconda的python3.6环境
conda create -n py36 python=3.6 anaconda
activate myenv
https://www.anaconda.com/download/#download
//
Install Boost.Python 1.57 一开始用的最新版本会出现问题,改用1.57可以
https://sourceforge.net/projects/boost/files/boost/1.57.0/boost_1_57_0.zip/download
解压
P.S.如果直接在下一步运行dlib的python setup.py install
照做就好,记得每次设置完环境变量重启开启控制台
我的系统中:
b2 installBOOST_ROOT=C:\software\boost\boost_1_57_0
BOOST_LIBRARYDIR=C:\software\boost\boost_1_57_0\libs
b2 -a --with-python address-model=64 toolset=msvc runtime-link=staticPath+C:\software\boost\boost_1_57_0\bin.v2
BOOST_LIBRARYDIR=C:\software\boost\boost_1_57_0\stage\lib
如果成功应该显示:
执行中出现Unknown compiler version - please run the configure tests and report the results
到boost/config/compiler/visualc.hpp根据VS版本修改
Install skimage
pip install scikit-image
Install Dlib 19.4
https://osdn.net/projects/sfnet_dclib/downloads/dlib/v19.4/dlib-19.4.zip/
//似乎经过上述步骤之后可以直接python setup.py install 甚至pip install dlib
Build Dlib library
解压进入目录
mkdir build
cd build
# If you don’t have Anaconda
cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=install ..
# If you have Anaconda installed on your machine
cmake -G "Visual Studio 14 2015 Win64" `
-DJPEG_INCLUDE_DIR=..\dlib\external\libjpeg `
-DJPEG_LIBRARY=..\dlib\external\libjpeg `
-DPNG_PNG_INCLUDE_DIR=..\dlib\external\libpng ` -DPNG_LIBRARY_RELEASE=..\dlib\external\libpng `
-DZLIB_INCLUDE_DIR=..\dlib\external\zlib `
-DZLIB_LIBRARY_RELEASE=..\dlib\external\zlib `
-DCMAKE_INSTALL_PREFIX=install ..
cmake --build . --config Release --target INSTALL
cd ..
Dlib的库文件在build的install下,使用VS时将其加入Include
Build Dlib examples
cd dlib-19.4/examples
mkdir build
cd build
# If you don’t have Anaconda
cmake -G "Visual Studio 14 2015 Win64" ..
# If you have Anaconda installed on your machine
cmake -G "Visual Studio 14 2015 Win64" `
-DJPEG_INCLUDE_DIR=..\..\dlib\external\libjpeg `
-DJPEG_LIBRARY=..\..\dlib\external\libjpeg `
-DPNG_PNG_INCLUDE_DIR=..\..\dlib\external\libpng ` -DPNG_LIBRARY_RELEASE=..\..\dlib\external\libpng `
-DZLIB_INCLUDE_DIR=..\..\dlib\external\zlib `
-DZLIB_LIBRARY_RELEASE=..\..\dlib\external\zlib `
..
cmake --build . --config Release
cd ..\..
时间巨长,需要耐心等待
//
//如果使用Anaconda/
Install Dlib python module
conda install -c conda-forge dlib=19.4
//
python setup.py install
在运行示例之前如果在之前的过程中根目录下没(不)有(会)产生shape_predictor_68_face_landmarks.bat文件,可以到这个地址下载
Test Dlib's C++ example
cd examples\build
.\Release\face_landmark_detection_ex.exe ..\..\shape_predictor_68_face_landmarks.dat ..\faces\2008_001009.jpg
Test Dlib's python example
cd dlib-19.4\python_examples
python face_landmark_detection.py ..\shape_predictor_68_face_landmarks.dat ..\examples\faces\
注意face_landmark_detection.py开头注释:
# The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
#
# This example program shows how to find frontal human faces in an image and
# estimate their pose. The pose takes the form of 68 landmarks. These are
# points on the face such as the corners of the mouth, along the eyebrows, on
# the eyes, and so forth.
#
# This face detector is made using the classic Histogram of Oriented
# Gradients (HOG) feature combined with a linear classifier, an image pyramid,
# and sliding window detection scheme. The pose estimator was created by
# using dlib's implementation of the paper:
# One Millisecond Face Alignment with an Ensemble of Regression Trees by
# Vahid Kazemi and Josephine Sullivan, CVPR 2014
# and was trained on the iBUG 300-W face landmark dataset.
#
# Also, note that you can train your own models using dlib's machine learning
# tools. See train_shape_predictor.py to see an example.
#
# You can get the shape_predictor_68_face_landmarks.dat file from:
# http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2
#
# COMPILING/INSTALLING THE DLIB PYTHON INTERFACE
# You can install dlib using the command:
# pip install dlib
#
# Alternatively, if you want to compile dlib yourself then go into the dlib
# root folder and run:
# python setup.py install
# or
# python setup.py install --yes USE_AVX_INSTRUCTIONS
# if you have a CPU that supports AVX instructions, since this makes some
# things run faster.
#
# Compiling dlib should work on any operating system so long as you have
# CMake and boost-python installed. On Ubuntu, this can be done easily by
# running the command:
# sudo apt-get install libboost-python-dev cmake
#
# Also note that this example requires scikit-image which can be installed
# via the command:
# pip install scikit-image
# Or downloaded from http://scikit-image.org/download.html.
Install OpenCV2.4.13
https://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.4.13/opencv-2.4.13.exe/download
可参考Air Band系列博文:(3)Air Band准备-下载安装
参考链接:
http://blog.csdn.net/sunmc1204953974/article/details/49976045
http://dlib.net/
http://www.learnopencv.com/install-dlib-on-windows/
https://hackernoon.com/building-a-facial-recognition-pipeline-with-deep-learning-in-tensorflow-66e7645015b8
https://medium.com/@ageitgey/machine-learning-is-fun-part-4-modern-face-recognition-with-deep-learning-c3cffc121d78
https://zhuanlan.zhihu.com/p/24567586
http://dlib.net/faq.html#Whywon'tthePythonbindingscompilework
http://www.codesofinterest.com/2016/10/installing-dlib-on-anaconda-python-on.html
https://stackoverflow.com/questions/17386880/does-anaconda-create-a-separate-pythonpath-variable-for-each-new-environment
https://stackoverflow.com/questions/20081338/how-to-activate-an-anaconda-environment
https://stackoverflow.com/questions/34906338/installing-anaconda-over-existing-python-system
https://conda.io/docs/user-guide/tasks/manage-python.html
http://www.boost.org/doc/libs/master/libs/python/doc/html/building/installing_boost_python_on_your_.html
http://www.boost.org/doc/libs/1_65_0/more/getting_started/windows.html
http://lib.csdn.net/article/python/62432
http://blog.csdn.net/zmdsjtu/article/details/72642521
https://askubuntu.com/questions/824834/how-to-install-dlib-for-python3-in-ubuntu-14-04
https://github.com/davisking/dlib/issues/218
http://blog.csdn.net/zhunianguo/article/details/53155890
https://stackoverflow.com/questions/30760889/unknown-compiler-version-while-compiling-boost-with-msvc-14-0-vs-2015
http://wiki.xglabc.com/Python%20dlib%E5%AE%89%E8%A3%85
http://www.jianshu.com/p/4d90a5a92d16
http://scikit-image.org/docs/dev/install.html
https://osdn.net/projects/sfnet_dclib/downloads/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2/