Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using openCV to overlay transparent image onto another image

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: enter image description here

Sources:

Background Image

Overlay

like image 560
Anthony Budd Avatar asked Nov 30 '16 18:11

Anthony Budd


People also ask

How do I blend images in OpenCV?

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.


1 Answers

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) 

added_image

like image 79
Manivannan Murugavel Avatar answered Sep 20 '22 15:09

Manivannan Murugavel