How do I adjust the alpha value after blending an image with a transparent background to a normal image (NOT transparent background)?

Viewed 98

I am working on a project to realize virtual makeup. I have a problem implementing the eyeliner part.

How should I change the alpha value(alpha_s, alpha_l)? in Python?

I want to adjust the alpha value so that the eyeliner on the face image may not be visible, it may look blurry, or I want to see it clearly.

Face image source is YouTube '뽐뽐뽐' (Apink's Bomi)

Below is python code, height and width of face, img are the same.

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' image looks like this.-> enter image description here

Some of the code result images(left eye) -> enter image description here

Please help me.

1 Answers

I solved the problem by referring to the site below.

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

Core code)

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

overlay is the original face image with virtualization applied, and face is the original face image.

Transparency can be adjusted according to the alpha value.

Note) I was able to realize the appearance of the eyeliner-shaped figure that fits the face image on the face image, but I could not implement the transparency adjustment.

To adjust the transparency, I tried to implement it like the code of the original text.

However, the transparency control was successfully implemented through the core code above.

Related