当前位置:网站首页>Dlib of face recognition framework

Dlib of face recognition framework

2022-04-23 16:35:00 Andrew p

1. Face detection is as follows

import dlib
from imageio import imread

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

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

# 1  It means to double the size of the picture , Easy to detect more faces 
dets = detector(img, 1)
print(' Detected.  %d  Personal face ' % 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)
		#  The first  0  Point and number  1  Coordinates of points 
		print('Part 0: {}, Part 1: {}'.format(shape.part(0), shape.part(1)))
		win.add_overlay(shape)

2. Generate face detector

detector = dlib.get_frontal_face_detector()# detector 

3. Generate feature predictor ,68 Dimensional

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

shape_predictor(landmark_model_path)

Parameters :landmark_model_path:68 features landmarks Model path

The official example is as follows :

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

Load all the models we need : A detector for finding faces , A shape predictor for finding face signs , So we can accurately locate the face

4. Start detection

# 1  It means to double the size of the picture , Easy to detect more faces 
dets = detector(img, 1)

5. return 68 Characteristic points

shape = predictor(img, d)

6. Draw feature points on the original graph

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)
		#  The first  0  Point and number  1  Coordinates of points 
		print('Part 0: {}, Part 1: {}'.format(shape.part(0), shape.part(1)))
		win.add_overlay(shape)

result

 

版权声明
本文为[Andrew p]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231624569457.html