我使用了一个名为人脸识别的模块来创建任何照片上嘴唇的轮廓,并希望修改图片以仅看到嘴唇而不是整个脸。然而,我不知道该怎么做。
我曾尝试将face_landmarks转换为numpy数组,然后显示它,但意识到它只显示嘴唇的坐标。
from PIL import Image, ImageDraw
import face_recognition
import numpy as np
# Load the jpg file into a numpy array
image =
face_recognition.load_image_file("/Users/23Athreyad/Documents/trump.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))
d.polygon(face_landmarks['bottom_lip'], fill=(150, 0, 0, 128))
print(face_landmarks['top_lip'])
pil_image.show()
预期的结果是嘴唇的放大图片,但我不确定如何实现这一点。
发布于 2019-01-16 02:56:19
如果你想提取界定嘴唇的矩形,你可以只获得矩形左上角的坐标(最小的x和y坐标)和右下角的坐标(最大的x和y坐标),并使用:
lip = image.crop((min_x, min_y, max_x, max_y))
请注意,image
是一个PIL Image
对象。
https://stackoverflow.com/questions/54204632
复制相似问题