Ubuntu14.04+dlib19.02+python+face landmark
2017-02-23 13:13
337 查看
1. 安装python
参考http://blog.csdn.net/liuxiaoheng1992/article/details/54407589 这篇blog给出的pythonpython setup.py install
提示我没有权限,所以我试着加上sudo
sudo python setup.py install
安装成功
可以在终端运行查看是否能够顺利导入:
python >>>import dlib
2. 运行face landmark官网的demo
官网人脸特征点检测demo代码如下:#!/usr/bin/python # 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. import sys import os import dlib import glob from skimage import io if len(sys.argv) != 3: print( "Give the path to the trained shape predictor model as the first " "argument and then the directory containing the facial images.\n" "For example, if you are in the python_examples folder then " "execute this program by running:\n" " ./face_landmark_detection.py shape_predictor_68_face_landmarks.dat ../examples/faces\n" "You can download a trained facial shape predictor from:\n" " http://dlib.net/files/shape_predictor_68_face_landmarks.dat.bz2") exit() predictor_path = sys.argv[1] faces_folder_path = sys.argv[2] detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor(predictor_path) win = dlib.image_window() for f in glob.glob(os.path.join(faces_folder_path, "*.jpg")): print("Processing file: {}".format(f)) img = io.imread(f) win.clear_overlay() win.set_image(img) # Ask the detector to find the bounding boxes of each face. The 1 in the # second argument indicates that we should upsample the image 1 time. This # will make everything bigger and allow us to detect more faces. dets = detector(img, 1) print("Number of faces detected: {}".format(len(dets))) for k, d in enumerate(dets): print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format( k, d.left(), d.top(), d.right(), d.bottom())) # Get the landmarks/parts for the face in box d. shape = predictor(img, d) print("Part 0: {}, Part 1: {} ...".format(shape.part(0), shape.part(1))) # Draw the face landmarks on the screen. win.add_overlay(shape) win.add_overlay(dets) dlib.hit_enter_to_continue()
根据代码提示,输入:
cd dlib cd python_examples ./face_landmark_detection.py shape_predictor_68_face_landmarks.dat ../examples/faces #shape_predictor_68_face_landmarks.dat放置位置自选,这样写就意味着shape_predictor_68_face_landmarks.dat放置再python_examples
demo运行结果如下:
3. 新建.py文件
如果要自己新建.py文件运行的话,如下操作:新建一个fr.py的文件,将官网给的demo代码copy进去
此时fr.py还未被编译?,然后在该目录下输入:
python fr.py chmod +x fr.py
变成如下:
这样就可以用了。
看下我们的结果,face_landmark.py我们的python文件:
输入:
./face_landmark.py shape_predictor_68_face_landmarks.dat ./image
这里的./image是放置图片的文件夹,不需要带.jpg后缀,看原文代码就知道。
faces_folder_path = sys.argv[2]
for f in glob.glob(os.path.join(faces_folder_path, "*.jpg")):
问题
解决办法:缺少动态连接库.so–cannot open shared object file: No such file or directory
sudo ln -s /usr/local/anaconda2/lib/libmkl_rt.so /usr/lib
解决啦。
解决办法:
发现pip install scikit-image没用,提示我已经安装过了。
然后我好加上sudo试试:
可以了。
问题:
解决办法:在~/.bashrc中加上:
export LD_LIBRARY_PATH="/usr/local/anaconda2/lib:$LD_LIBRARY_PATH"
博主试过,在/etc/profile中加上上面指令,没用,而且会和我的cuda-7.5/lib发生冲突,就是重启或者注销系统的时候进不去系统,怀疑就是路径发生冲突了,/etc/profile是全局的,而~/.bashrc是局部的。所以当我添加到~/.bashrc里,就可以使用了。
参考:Intel MKL FATAL ERROR: Cannot load libmkl_avx.so or libmkl_def.so.
相关文章推荐
- ubuntu14.04 + dlib19.2+【 C++ 】+Face Landmark Detection
- 【Dlib+Python+Ubuntu】人脸landmark
- Ubuntu14.04 交叉编译Python2.7.2 for arm
- Ubuntu14.04中安装python的gui(idle),并安装jieba,numpy,scipy和matplotlib
- [转][linux(ubuntu14.04)+GPU+cuda6.5+caffe+openCV2.4.9+matlab2013b+python2.7的新手配置转]
- ubuntu14.04环境下python3 Image.show()不显示图片问题
- ubuntu14.04 安装mod_python
- Ubuntu 14.04---Nginx+uWsgi+Django+Python+MongoDB+m
- Ubuntu 14.04 安装 Python3
- 在ubuntu14.04上安装python3.4.3
- ubuntu14.04 python2.7 安装配置OpenCV3.0
- linux(ubuntu14.04)+GPU+cuda6.5+caffe+openCV2.4.9+matlab2014a+python的新手配置(修改版)
- ubuntu14.04安装python爬虫框架Scrapy
- 在Ubuntu 14.04 64bit上安装python mongoDB模块
- linux(ubuntu14.04)+GPU+cuda6.5+caffe+openCV2.4.9+matlab2014a+python的新手配置
- Ubuntu 14.04---Nginx+uWsgi+Django+Python+MongoDB
- [zz]Python 3.4 and Pillow 2.4 with JPEG2000 (openjpeg 2) support in Ubuntu 14.04
- 在Ubuntu 14.04 64bit下用Python搭建数据科学研究环境
- 如何在Ubuntu14.04+上编译同时支持python2和python3的vim?
- Ubuntu14.04增加右键菜单=>“run_on_python”