Digital makeup

Digital makeup, using face_recognition.

The environment

  • Windows 10
  • Face_recognition 1.2.2

Environmental installation

Face_recognition installation

Use the following command:

pip3 install face_recognition

This one takes a long time to install.

Results the preview

The complete code

#coding=utf-8
# Digital makeup
import face_recognition
from PIL import Image, ImageDraw

Load images into numpy Array
image = face_recognition.load_image_file("img/image.png")

# Identify facial features
face_landmarks_list = face_recognition.face_landmarks(image)

for face_landmarks in face_landmarks_list:
    pil_image = Image.fromarray(image)
    d = ImageDraw.Draw(pil_image, 'RGBA')

    # Draw eyebrows
    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)

    # Paint lips
    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)

    # Draw eyes
    d.polygon(face_landmarks['left_eye'], fill=(255.255.255.30))
    d.polygon(face_landmarks['right_eye'], fill=(255.255.255.30))

    # Paint eyeliner
    d.line(
        face_landmarks['left_eye'] + [face_landmarks['left_eye'] [0]],
        fill=(0.0.0.110),
        width=6)
    d.line(
        face_landmarks['right_eye'] + [face_landmarks['right_eye'] [0]],
        fill=(0.0.0.110),
        width=6)

    pil_image.show()

Copy the code

Resource portal

  • Pay attention to [== do a gentle program ape ==] public account
  • In [== do a tender program ape ==] public account background reply [Python information] [2020 autumn recruit] can get the corresponding surprise oh!
  • Build their own blog address: nightmare back to life blog

“❤️ thank you.”

  • Click “like” to support it, so that more people can see this content.
  • Share your thoughts with me in the comments section, and record your thought process in the comments section