Python 化妆

face-recognition 模块人脸化妆

这里写图片描述
代码如下:

from PIL import Image, ImageDraw

# 导入face_recogntion模块,可用命令安装 pip install face_recognition

import face_recognition
#
##将jpg文件加载到numpy数组中

image = face_recognition.load_image_file('12.jpg')
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')

    ##让眉毛变成了一场噩梦
#    
    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=1)
#    
#    d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=1)

    #光泽的嘴唇

    d.polygon(face_landmarks['top_lip'], fill=(180, 0, 0, 128))

    d.polygon(face_landmarks['bottom_lip'], fill=(180, 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)

    #闪耀眼睛

    d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30))

    d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30)) 
    #涂一些眼线

#    d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=1)
#    
#    d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110), width=1)

pil_image.show(image)

from PIL import Image, ImageDraw

# 导入face_recogntion模块,可用命令安装 pip install face_recognition

import face_recognition
#
##将jpg文件加载到numpy数组中

image = face_recognition.load_image_file('/home/260207/桌面/photo/12.jpg')
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')

    ##让眉毛变成了一场噩梦
#    
    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=1)
#    
#    d.line(face_landmarks['right_eyebrow'], fill=(68, 54, 39, 150), width=1)

    #光泽的嘴唇

    d.polygon(face_landmarks['top_lip'], fill=(180, 0, 0, 128))

    d.polygon(face_landmarks['bottom_lip'], fill=(180, 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)

    #闪耀眼睛

    d.polygon(face_landmarks['left_eye'], fill=(255, 255, 255, 30))

    d.polygon(face_landmarks['right_eye'], fill=(255, 255, 255, 30)) 
    #涂一些眼线

#    d.line(face_landmarks['left_eye'] + [face_landmarks['left_eye'][0]], fill=(0, 0, 0, 110), width=1)
#    
#    d.line(face_landmarks['right_eye'] + [face_landmarks['right_eye'][0]], fill=(0, 0, 0, 110), width=1)

pil_image.show(image)

结果图片:
这里写图片描述

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值