-
Notifications
You must be signed in to change notification settings - Fork 1
/
offline_face_landmark_detection.py
37 lines (30 loc) · 1.21 KB
/
offline_face_landmark_detection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 离线版本:基于68点的人脸检测
import sys
import os
import dlib
import glob
# 重点!!!!:基于自己的路径进行调整
predictor_path = './model/shape_predictor_68_face_landmarks.dat'
faces_folder_path = './data/image/faces'
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 = dlib.load_rgb_image(f)
win.clear_overlay()
win.set_image(img)
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()
print("执行完成")