How can I overlay a transparent PNG onto another image without losing it's transparency using openCV in python?
import cv2 background = cv2.imread('field.jpg') overlay = cv2.imread('dice.png') # Help please cv2.imwrite('combined.png', background)
Desired output:
Sources:
Background Image
Overlay
Like before, we start by importing the cv2 module, followed by reading both images and resizing them to be 400×400. We will then display the second image in a window called “blend“. It will be the one we will use every time we update the weights to display the resulting image.
import cv2 background = cv2.imread('field.jpg') overlay = cv2.imread('dice.png') added_image = cv2.addWeighted(background,0.4,overlay,0.1,0) cv2.imwrite('combined.png', added_image)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With