当前位置:网站首页>人脸识别框架之dlib

人脸识别框架之dlib

2022-04-23 16:25:00 andrew P

1.人脸检测如下

import dlib
from imageio import imread

detector = dlib.get_frontal_face_detector()#检测器
predictor_path = 'shape_predictor_68_face_landmarks.dat'
predictor = dlib.shape_predictor(predictor_path)#预测器
win = dlib.image_window()
path ='111.jpg'

img = imread(path)
win.clear_overlay()
win.set_image(img)

# 1 表示将图片放大一倍,便于检测到更多人脸
dets = detector(img, 1)
print('检测到了 %d 个人脸' % len(dets))
for i, d in enumerate(dets):
		print('- %d: Left %d Top %d Right %d Bottom %d' % (i, d.left(), d.top(), d.right(), d.bottom()))
		shape = predictor(img, d)
		# 第 0 个点和第 1 个点的坐标
		print('Part 0: {}, Part 1: {}'.format(shape.part(0), shape.part(1)))
		win.add_overlay(shape)

2.生成面部检测器

detector = dlib.get_frontal_face_detector()#检测器

3.生成特征预测器,68维度的

predictor_path = 'shape_predictor_68_face_landmarks.dat'
predictor = dlib.shape_predictor(predictor_path)#预测器

shape_predictor(landmark_model_path)

参数:landmark_model_path:68特征landmarks模型path

官方例子如下:

http://dlib.net/face_alignment.py.html

# Load all the models we need: a detector to find the faces, a shape predictor
# to find face landmarks so we can precisely localize the face

加载我们需要的所有模型:一个用于查找人脸的检测器,一个用于查找人脸标志的形状预测器,这样我们就可以精确定位人脸

4.开始检测

# 1 表示将图片放大一倍,便于检测到更多人脸
dets = detector(img, 1)

5.返回68个特征点

shape = predictor(img, d)

6.将特征点画到原来的图上

for i, d in enumerate(dets):
		print('- %d: Left %d Top %d Right %d Bottom %d' % (i, d.left(), d.top(), d.right(), d.bottom()))
		shape = predictor(img, d)
		# 第 0 个点和第 1 个点的坐标
		print('Part 0: {}, Part 1: {}'.format(shape.part(0), shape.part(1)))
		win.add_overlay(shape)

结果

 

版权声明
本文为[andrew P]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_41166909/article/details/124330874