偶然看到一篇文章,說是可以實時人臉識別,很有興趣就自己按照文章開始動手人臉識別,但是實現(xiàn)過程中遇到了幾個問題這里做個總結(jié),希望可以幫助到大家
安裝face_recognition這個之前需要先安裝編譯dlib,如果沒有安裝dlib,那么我們先來裝dlib,但是按照dlib的時候多數(shù)情況會出現(xiàn) not found boost。這是我們并沒有按照boost,那么我們按順序來,先裝boost
1:sudo apt-get install libboost-all-dev
安裝成功后我們開始編譯dlib
1:git clone https://github.com/davisking/dlib.git
2:cd dlib
3:mkdir build
4:cd build
5:cmake .. -DDLIB_USE_CUDA=0 -DUSE_AVX_INSTRUCTIONS=1
6:cmake --build .(注意中間有個空格)
7:cd ..
8:python setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA
如果出現(xiàn) Cannot allocate memory 這個錯誤,我們需要先進(jìn)行設(shè)置虛擬內(nèi)存或者直接增大內(nèi)存
設(shè)置虛擬內(nèi)存
先查看內(nèi)存 free -m

1:dd if=/dev/zero of=/dlib bs=1024 count=2048000
2:mkswap /dlib
3:swapon /dlib
再次查看內(nèi)存 free -m

搞定內(nèi)存問題后,再次運行python setup.py install --yes USE_AVX_INSTRUCTIONS --no DLIB_USE_CUDA,成功編譯dlib(Finished processing dependencies for dlib==19.7.99),開始安裝 face_recognition?
1:pip install face_recognition
2:安裝成功
3:關(guān)掉swap?
swapoff /dlib
運行代碼的時候可能會遇到 no module name scipy
這個時候自己裝scipy這個庫就好了
如果pip裝不上就要先用下面兩個命令編譯庫,給個鏈接:http://blog.csdn.net/shomy_liu/article/details/48543449
sudo apt-get build-dep python-numpy
sudo apt-get build-dep python-scipy
然后再次 pip install scipy 就OK了
這樣就可以開始自己的人臉識別了~