-
Notifications
You must be signed in to change notification settings - Fork 0
/
face_landmarks.py
32 lines (22 loc) · 1.11 KB
/
face_landmarks.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
import PIL.Image
import PIL.ImageDraw
import face_recognition
# Load the jpg file into a numpy array
image = face_recognition.load_image_file("group_pic2.jpg")
# Find all facial features in all the faces in the image
face_landmarks_list = face_recognition.face_landmarks(image)
number_of_faces = len(face_landmarks_list)
print("I found {} face(s) in this photograph.".format(number_of_faces))
# Load the image into a Python Image Library object so that we can draw on top of it and display it
pil_image = PIL.Image.fromarray(image)
# Create a PIL drawing object to be able to draw lines later
draw = PIL.ImageDraw.Draw(pil_image)
# Loop over each face
for face_landmarks in face_landmarks_list:
# Loop over each facial feature (eye, nose, mouth, lips, etc)
for name, list_of_points in face_landmarks.items():
# Print the location of each facial feature in this image
print("The {} in this face has the following points: {}".format(name, list_of_points))
# Let's trace out each facial feature in the image with a line!
draw.line(list_of_points, fill="blue", width=3)
pil_image.show()