说明:本人在安装过程中遇到各种各样的问题,经过多次折腾,终于完成dlib在python中的配置,在此过程中多谢各位大牛写的文章,在此对自己的配置过程进行进行记录与说明,希望对后来人具有一定的参考。

1、下载python3.5.4,下载地址: https://www.python.org/downloads/

目前python有多个版本,作者最初装的3.7版本,但一直为配置成功,故降低版本,选择3.5版本。

python3.5+dlib19.4配置教程

2、下载dlib的whl文件,whl可以直接安装,无需编译,在查询的大部分资料中都提示说需要采用CMake和VS2015以上版本进行编译,dlib下载地址:http://dlib.net/files/

python3.5+dlib19.4配置教程

3、安装python,注意添加环境路径

4、验证python安装是否成功,

python3.5+dlib19.4配置教程

5、安装dlib-19.4.0-cp35-cp35m-win_amd64.whl

python3.5+dlib19.4配置教程

6、测试dlib,在dlib官网下载测试文件,下载example,如下:

import sys
import os
import dlib
import glob
from skimage import io


current_path = os.getcwd() 
# 获取当前路径
predictor_path =current_path+"\\shape_predictor_68_face_landmarks.dat"
face_rec_model_path = current_path+"\\dlib_face_recognition_resnet_model_v1.dat"
faces_folder_path = current_path+"\\image"

# Load all the modelswe need: a detector to find the faces, a shape predictor
# to find face landmarks so we can precisely localize the face, and finally the
# face recognition model.
detector =dlib.get_frontal_face_detector()
sp = dlib.shape_predictor(predictor_path)
facerec = dlib.face_recognition_model_v1(face_rec_model_path)


# Now process all the images
for f in glob.glob(os.path.join(faces_folder_path,"*.jpg")):
   
print("Processing file: {}".format(f))
    img = io.imread(f)

    win = dlib.image_window()
    win.clear_overlay()
    win.set_image(img)

   
# Ask the detector to find the bounding boxes of eachface. The 1 in the
    # second argument indicates that weshould upsample the image 1 time. This
    # will make everything bigger andallow us to detect more faces.
   
dets = detector(img, 1)
   
print("Number of faces detected: {}".format(len(dets)))
    shape2=sp(img,dets[
0])
    win.add_overlay(shape2)
    win.add_overlay(dets)

   
# Now process each face we found.
   
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 = sp(img,d)
       
# Draw the face landmarks on the screen so we can seewhat face is currently being processed.
        #win.clear_overlay()
        #win.add_overlay(d)
       
win.add_overlay(shape)

       
# Compute the 128D vector that describes the face in imgidentified by
        # shape.  In general, if two face descriptor vectorshave a Euclidean
        # distance between them less than0.6 then they are from the same
        # person, otherwise they are fromdifferent people. Here we just print
        # the vector to the screen.
       
face_descriptor = facerec.compute_face_descriptor(img,shape)
       
print(face_descriptor)

   
dlib.hit_enter_to_continue()

7、运行该文件,错误如下,

安装scikit-image,pip installscikit-image

python3.5+dlib19.4配置教程

8、安装完成后提示缺少scipy库,pip install scipy安装该库。

python3.5+dlib19.4配置教程

python3.5+dlib19.4配置教程

9、安装完成后重新运行程序,结果如下:

python3.5+dlib19.4配置教程

 


配置过程如有问题请咨询qq:3511353029

公众号:dadiSurvey

淘宝:https://shop165937777.taobao.com/?spm=a230r.7195193.1997079397.13.ZnblPS

博客:https://blog.csdn.net/zz_z123/article/details/79859954


相关文章: