基于Python和命令行人脸识别项目(系列三) (2)

基于Python和命令行人脸识别项目(系列三)

案例二:给鞠婧祎涂美妆

在knowe_people文件夹中创建digital_makeup.py文件并写入以下代码:

from PIL import Image, ImageDraw
import face_recognition

# Load the jpg file into a numpy array
image = face_recognition.load_image_file("鞠婧祎.jpg")

# Find all facial features in all the faces in the image
face_landmarks_list = face_recognition.face_landmarks(image)

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

    # Make the eyebrows into a nightmare
    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)

    # Gloss the 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)

    # Sparkle the eyes
    d.polygon(face_landmarks[\'left_eye\'], fill=(255, 255, 255, 30))
    d.polygon(face_landmarks[\'right_eye\'], fill=(255, 255, 255, 30))

    # Apply some 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()
然后终端切换到knowe_people目录下,输入以下命令,弹出窗口如下:

基于Python和命令行人脸识别项目(系列三)

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzgjys.html