-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface_landmarks.py
41 lines (32 loc) · 1.36 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
33
34
35
36
37
38
39
40
41
# -*- coding: utf-8 -*-
"""
Created on Thu Jun 8 14:35:41 2023
@author: slbouknight
"""
import face_recognition
from PIL import Image, ImageDraw
# Load image into numpy array
face_image = face_recognition.load_image_file('images/samples/rihanna.jpg')
# Obtain list of face landmarks
face_landmarks_list = face_recognition.face_landmarks(face_image)
# Display landmarks
print(face_landmarks_list)
# Iterate through all face landmarks
for face_landmarks in face_landmarks_list:
# Convert np array to pil image and make a DrawObject
pil_image = Image.fromarray(face_image)
d = ImageDraw.Draw(pil_image)
# Connect each face landmark point using a white line
d.line(face_landmarks['chin'], fill=(0, 255, 0), width=2)
d.line(face_landmarks['left_eyebrow'], fill=(0, 255, 0), width=2)
d.line(face_landmarks['right_eyebrow'], fill=(0, 255, 0), width=2)
d.line(face_landmarks['nose_bridge'], fill=(0, 255, 0), width=2)
d.line(face_landmarks['nose_tip'], fill=(0, 255, 0), width=2)
d.line(face_landmarks['left_eye'], fill=(0, 255, 0), width=2)
d.line(face_landmarks['right_eye'], fill=(0, 255, 0), width=2)
d.line(face_landmarks['top_lip'], fill=(0, 255, 0), width=2)
d.line(face_landmarks['bottom_lip'], fill=(0, 255, 0), width=2)
# Show final image
pil_image.show()
# Save image
pil_image.save('images/samples/abhi_landmarks.jpg')