Skip to content

Instantly share code, notes, and snippets.

@KevinPatel04
Last active April 26, 2020 18:15
Show Gist options
  • Save KevinPatel04/39cc6bdcb61584b8449a7decb8a076d1 to your computer and use it in GitHub Desktop.
Save KevinPatel04/39cc6bdcb61584b8449a7decb8a076d1 to your computer and use it in GitHub Desktop.
Face Makeup
•
├── images
│   ├── test-1.jpg
│   └── test-2.jpg
└── face-makeup-on-image.py
# importing required libraries
import face_recognition
from PIL import Image, ImageDraw
# Load the jpg file into a numpy array
face_image = face_recognition.load_image_file("images/test-1.jpg")
# get the face landmarks list
face_landmarks_list = face_recognition.face_landmarks(face_image)
# print all the face landmarks
print(face_landmarks_list)
# for loop tointerate through all land marks in the list
for face_landmarks in face_landmarks_list:
# convert numpy array to pil image
# create a Draw Object with Alpha Mode for Translucency
pil_image = Image.fromarray(face_image)
d = ImageDraw.Draw(pil_image, "RGBA")
# Make left, righteyebrows darker
# Polygon on top and line on bottom with dark color
d.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128))
d.polygon(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 128))
d.line(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 150), width=5)
d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=5)
# Add lipstick to top and bottom lips
# using red polygons and lines filled with red
d.polygon(face_landmarks['top_lip'], fill=(150,0,0,128))
d.polygon(face_landmarks['bottom_lip'], fill=(150,0,0,128))
d.line(face_landmarks['top_lip'], fill=(150,0,0,64), width = 8)
d.line(face_landmarks['bottom_lip'], fill=(150,0,0,64), width = 8)
# Sparkle the eyes
# using white polygon
d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30))
d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30))
# Apply some black eyeliner
d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=3)
d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110), width=3)
# display the image
pil_image.show()
# You can also asave a copy of the new image to diskk
pil_image.save("Face_With_Makeup.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment