gpt4 book ai didi

python - 有没有办法从 face_recognition 中平滑面部特征?也许通过 PIL?

转载 作者:太空宇宙 更新时间:2023-11-04 02:06:22 24 4
gpt4 key购买 nike

我正在尝试制作一个可以用图像填充眼睛的眼睛替换程序。为了找到眼睛,我使用了 Ageitgey 的 face_recognition。然而,眼睛检测结果非常参差不齐。

(我不是在谈论抗锯齿,顺便说一句。我稍后会使用 super 采样来解决这个问题)

这是我的一小段代码:

from PIL import Image, ImageDraw
import face_recognition

image = face_recognition.load_image_file("media/test_input_image.jpg")

face_landmark_list = face_recognition.face_landmarks(image)

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

d.polygon(face_landmarks["right_eye"], fill=(255, 0, 0, 255))

pil_image.show()

示例: [Daniel 令人惊讶的可怕眼睛选择不当]

enter image description here

我希望它看起来更平滑。我希望获得类似左侧绿眼的效果,但目前正在获得右侧的红眼。 (绿色的眼睛是用 Gimp 绘制的。)

那么,基本上,有没有办法从红色结果变成绿色?

最佳答案

方法 1:(简单)

  • 使用二次或三次回归来拟合使用左/右和 2 个上点的曲线
  • 对左/右和 2 个较低的点执行相同的操作。
  • 抽样取决于您希望每个样本获得多少分。 enter image description here

示例 python 代码:

import numpy.polynomial.polynomial as poly
import numpy as np
import matplotlib.pyplot as plt

# Grab x, y coordinates from eyes in face_recognition result
# Here is the example point.
x = np.array([1, 2, 4, 5])
y = np.array([1, 1.5, 1.5, 1])

# x_new: upsampling 40 points from x
x_new = np.linspace(x[0], x[-1], num=len(x)*10)

coefs = poly.polyfit(x, y, 3)
y_new = poly.polyval(x_new, coefs)

plt.plot(x_new, y_new,'r-')
plt.plot(x,y,'o')
plt.show()

方法二:(难)

  • 使用 dlib,重新训练对象检测器以仅检测具有 6 个以上点的眼睛,例如单眼64分,效果更流畅。

关于python - 有没有办法从 face_recognition 中平滑面部特征?也许通过 PIL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54611946/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com