I've been using opencv to paste a png image over a background. My target is to simulate a sort of plastic bag underwater. In that way, I would like to apply Alpha in order to have the png image semi-transparent over the background, but when I do, the black mask of the png becomes transparent too.
y1, y2 = yoff, yoff + png.shape[0]
x1, x2 = xoff, xoff + png.shape[1]
alpha_png = png[:, :, 3] / 255.0
alpha_bg = 0.5 - alpha_png
bg_copy = bg.copy()
for c in range(0, 3):
bg_copy[y1:y2, x1:x2, c] = (alpha_png * png[:, :, c] + alpha_bg * bg_copy[y1:y2, x1:x2, c])
cv2.imwrite("result.png", bg_copy)
I found this code online, and I changed the alpha_bg in order to make the image more or less transparent.
I need to remove the black semi-transparent background, but the rest of the png should remain semi-transparent, plus the bag should get the background green color or underwater color (But I'll work later on this).
Any suggestion is really appreciated, also considering to use PIL instead of opencv.
Edit: