0

I am using cvzone to overlay one transparent image onto another image and then saving them using PIL, but the resultant image does not have a transparent background

import cvzone
import cv2
import numpy as np
import PIL
from PIL import Image

imgBack = cv2.imread("Robot/Body/0_base colour.png")
imgFront = cv2.imread("Robot/Clothing/2_tux.png", cv2.IMREAD_UNCHANGED)

new_size = (300, 300)
resized_img_front = cv2.resize(imgFront, new_size)
resized_img_back = cv2.resize(imgBack, new_size)

result_img = cvzone.overlayPNG(resized_img_back, resized_img_front)
final_img = Image.fromarray(result_img)
final_img.save("combined.png")
cv2.imshow("back", result_img)
cv2.waitKey(0)

Am i missing something that i also need to do to make my final image transparent as well, like is there any subroutine for that

sidewala
  • 61
  • 4
  • https://stackoverflow.com/questions/5324647/how-to-merge-a-transparent-png-image-with-another-image-using-pil – Larry the Llama Dec 11 '21 at 06:29
  • recipe for opencv: https://github.com/opencv/opencv/issues/20780 and avoid `cvzone`. anything that's called `overlayPNG` can't be of high quality because the overlay has nothing to do with PNG files and everything to do with images that have an alpha channel, hence `PNG` has no place in the name of such a function. – Christoph Rackwitz Dec 11 '21 at 11:44
  • oh and you should expect cv.resize to **not** correctly resize anything with an alpha channel, because it is **unaware** of the alpha channel having **special** meaning. – Christoph Rackwitz Dec 11 '21 at 11:45

0 Answers0