【发布时间】:2019-04-21 13:36:50
【问题描述】:
我想裁剪上唇和下唇并将其保存到一张图像中。 我正在使用这个 GitHub 库face_recognition
这是代码:
from PIL import Image, ImageDraw
import face_recognition
# Load the jpg file into a numpy array
image = face_recognition.load_image_file("me.jpg")
# Find all facial features in all the faces in the image
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')
# Gloss the lips
d.polygon(face_landmarks['top_lip'], fill=(150, 0, 0, 128), outline=None)
d.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128), outline=None)
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)
# cropped_top_lip = image.crop(face_landmarks['top_lip'])
# cropped_top_lip.save('top_lip.jpg')
# cropped_bottom_lip = image.crop(face_landmarks['bottom_lip'])
# cropped_bottom_lip.save('bottom_lip.jpg')
pil_image.save('me2.jpg')
这会返回完整的图像,我只想要嘴唇部分。
这是face_landmarks['top_lip']的打印:
[(498, 937), (546, 926), (597, 924), (637, 930), (676, 922), (726, 922), (772, 929), (756, 935), (677, 940), (637, 946), (597, 942), (516, 942)]
【问题讨论】:
标签: python image-processing face-recognition