digital_makeup.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334
  1. from PIL import Image, ImageDraw
  2. import face_recognition
  3. # Load the jpg file into a numpy array
  4. image = face_recognition.load_image_file("biden.jpg")
  5. # Find all facial features in all the faces in the image
  6. face_landmarks_list = face_recognition.face_landmarks(image)
  7. for face_landmarks in face_landmarks_list:
  8. pil_image = Image.fromarray(image)
  9. d = ImageDraw.Draw(pil_image, 'RGBA')
  10. # Make the eyebrows into a nightmare
  11. d.polygon(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 128))
  12. d.polygon(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 128))
  13. d.line(face_landmarks['left_eyebrow'], fill=(68, 54, 39, 150), width=5)
  14. d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=5)
  15. # Gloss the lips
  16. d.polygon(face_landmarks['top_lip'], fill=(150, 0, 0, 128))
  17. d.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128))
  18. d.line(face_landmarks['top_lip'], fill=(150, 0, 0, 64), width=8)
  19. d.line(face_landmarks['bottom_lip'], fill=(150, 0, 0, 64), width=8)
  20. # Sparkle the eyes
  21. d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30))
  22. d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30))
  23. # Apply some eyeliner
  24. d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=6)
  25. d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110), width=6)
  26. pil_image.show()