【问题标题】:How do I adjust the alpha value after blending an image with a transparent background to a normal image (NOT transparent background)?将具有透明背景的图像与普通图像(非透明背景)混合后如何调整 alpha 值?
【发布时间】:2020-08-02 13:52:06
【问题描述】:

我正在做一个项目来实现虚拟化妆。 我在使用眼线笔部分时遇到问题。

我应该如何更改 alpha 值(alpha_s,alpha_l)?在 Python 中?

我想调整 alpha 值,使脸部图像上的眼线可能不可见、可能看起来模糊,或者我想看清楚。

人脸图片来源是 YouTube '뽐뽐뽐' (Apink's Bomi)

下面是python代码,人脸的高宽,img都是一样的。

face = cv2.imread('./image/ex1.png')
img = cv2.imread('./result_3.png',-1) ## It is shaped like a left eyeliner and has a transparent background.

x_offset = y_offset = 0
alpha_s = img[:, :, 3] / 255.0
alpha_l = 1.0 - alpha_s
for c in range(0, 3):

    face[y_offset:y_offset+img.shape[0], x_offset:x_offset+img.shape[1], c] = \
    (alpha_s * img[:, :, c] + alpha_l * face[y_offset:y_offset+img.shape[0], 
    x_offset:x_offset+img.shape[1], c])
cv2.imshow('result', face)
cv2.waitKey(0)
cv2.destroyAllWindows()

'result_3.png' 图像看起来像这样。-> enter image description here

部分代码结果图片(左眼) -> enter image description here

请帮帮我。

【问题讨论】:

    标签: python opencv image-processing


    【解决方案1】:

    我通过参考下面的网站解决了这个问题。

    https://www.pyimagesearch.com/2016/03/07/transparent-overlays-with-opencv/

    核心代码)

    cv2.addWeighted(overlay, alpha, face, 1 - alpha,0, face)
    

    overlay 是应用虚拟化的原始人脸图像,face 是原始人脸图像。

    可根据alpha值调整透明度。

    注意) 可以在人脸图像上实现适合人脸图像的眼线型身材的外观,但无法实现透明度调整。

    为了调整透明度,我试着像原文的代码那样实现。

    但是,通过上面的核心代码成功实现了透明度控制。

    【讨论】:

      猜你喜欢
      • 2012-05-26
      • 2011-11-10
      • 2020-12-20
      • 2016-12-08
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多