有没有办法从face_recognition平滑脸部界标?也许通过PIL? [英] Is there a way to smooth out face landmarks from face_recognition? Maybe via PIL?

查看:119
本文介绍了有没有办法从face_recognition平滑脸部界标?也许通过PIL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to make an eye-replacement program that can fill eyes with an image. For finding the eyes, I am using face_recognition by Ageitgey. However, the eye detection comes out very jagged.

(顺便说一句,我不是在谈论抗锯齿.稍后我将使用超级采样来解决)

(I'm not talking about anti-aliasing, btw. I'll use super-sampling to solve that later)

这是我的一小段代码:

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

示例:[丹尼尔惊讶地挑剔的眼睛]

example: [Daniel's surprisingly terrifying badly selected eyes]

我希望它看起来更平滑.我正在寻求实现左侧绿眼之类的功能,但目前正在右侧实现红眼技术. (用Gimp吸引了绿眼睛.)

I want it looking more smooth. I am looking to achieve something like the green eye on the left, but am currently getting the red eye on the right. (The green eye was drawn on with Gimp.)

因此,基本上,有没有办法从红色结果变为绿色?

So, basically, is there a way to go from the red result, to the green?

推荐答案

方法1 :(轻松)

  • 使用二次或三次回归来拟合使用左/右和2个上点的曲线
  • 对左/右和两个较低的点做同样的事情.
  • 采样取决于每个采样点需要多少个点.
  • Use quadratic or cubic regression to fit a curve using left/right and 2 upper points
  • Do the same thing for left/right and 2 lower points.
  • Sampling depends on how many points you want for each.

示例python代码:

Sample python code:

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点,您将获得更流畅的效果.

这篇关于有没有办法从face_recognition平滑脸部界标?也许通过PIL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆