Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odixon/74257fc9abfc42ef76b1299760485d62 to your computer and use it in GitHub Desktop.
Save odixon/74257fc9abfc42ef76b1299760485d62 to your computer and use it in GitHub Desktop.
find_facial_features_in_picture.py
from PIL import Image, ImageDraw
import face_recognition
image_file = 'obama.jpg'
# Load the jpg file into a numpy array
image = face_recognition.load_image_file(image_file)
# Find all facial features in all the faces in the image
face_landmarks_list = face_recognition.face_landmarks(image)
print("I found {} face(s) in this photograph.".format(len(face_landmarks_list)))
pil_image = Image.fromarray(image)
d = ImageDraw.Draw(pil_image)
for face_landmarks in face_landmarks_list:
# Print the location of each facial feature in this image
facial_features = [
'chin',
'left_eyebrow',
'right_eyebrow',
'nose_bridge',
'nose_tip',
'left_eye',
'right_eye',
'top_lip',
'bottom_lip'
]
for facial_feature in facial_features:
print("The {} in this face has the following points: {}".format(facial_feature, face_landmarks[facial_feature]))
# Let's trace out each facial feature in the image with a line!
for facial_feature in facial_features:
d.line(face_landmarks[facial_feature], width=5)
# Display drawed image
pil_image.show()
# pil_image.save('test.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment