有没有一种方法可以从人脸识别中消除人脸标志?也许通过皮尔?

2024-06-01 01:37:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试做一个眼睛替代计划,可以填补眼睛与图像。为了找到眼睛,我使用了Ageitgey的面部识别。然而,眼睛的检测结果非常参差不齐。

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

下面是我的一点代码:

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()

例子:【丹尼尔令人惊讶的糟糕的眼睛】

enter image description here

我希望它看起来更光滑。我希望实现一些像左边的绿眼,但是现在右边有红眼。(绿眼被金普吸引住了。)

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


Tags: 图像imageimportpillist计划face眼睛
1条回答
网友
1楼 · 发布于 2024-06-01 01:37:04

方法1:(简单)

  • 使用二次或三次回归使用左/右和两个上点拟合曲线
  • 对左/右和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()

方法2:(困难)

  • 使用dlib,重新训练目标检测器,只检测超过6个点的眼睛,例如一只眼睛有64个点,你会得到更平滑的结果。在

相关问题 更多 >