python 调用dlib库人脸识别+68特征点

调用dlib自带的库进行人脸识别,且绘制人脸的68个特征点

# -*- coding: UTF-8 -*-
import dlib
from skimage import io
import matplotlib.pyplot as plt
from skimage.draw import polygon_perimeter

detector = dlib.get_frontal_face_detector()
landmark_predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
sample_image = io.imread('p2.jpg')
faces = detector(sample_image, 1)
for d in faces:#画出人脸区域
    rr, cc = polygon_perimeter([d.top(), d.top(), d.bottom(), d.bottom()], [d.right(), d.left(), d.left(), d.right()])
    sample_image[rr, cc] = (0, 255, 0)
io.imsave('d:/ps2.jpg', sample_image)

for k, d in enumerate(faces):#画出68个特征点
    shape = landmark_predictor(sample_image, d)
    for i in range(68):
        pt = shape.part(i)
        plt.plot(sample_image, pt.x, pt.y, 'ro')
plt.imshow(sample_image)
plt.show()

代码及特征点训练库下载链接:

https://download.csdn.net/download/qq_29848393/11045511

 

你可能感兴趣的:(python 调用dlib库人脸识别+68特征点)