Skip to content

Instantly share code, notes, and snippets.

@PeaceAndHiLight
Created January 24, 2016 10:56
Show Gist options
  • Save PeaceAndHiLight/89b0211ef2eb0710a581 to your computer and use it in GitHub Desktop.
Save PeaceAndHiLight/89b0211ef2eb0710a581 to your computer and use it in GitHub Desktop.
Add png Image On Jpeg Image
#coding: utf-8
import cv2
import numpy as np
img = cv2.imread('B.jpg', cv2.IMREAD_COLOR)
logo = cv2.imread('logo2.png', cv2.IMREAD_UNCHANGED)
#Get Height And Width of Logo
logoHeight, logoWidth = logo.shape[:2]
#print 'logoWidth = ' + str(logoWidth) + ' logoHeight = ' + str(logoHeight)
#Get Just Alpha
alpha = logo[:,:,3]
alpha = cv2.cvtColor(alpha, cv2.COLOR_GRAY2BGR)
alpha = alpha / 255.0
#Get BGR From logo (Remove Alpha)
logo = logo[:,:,:3]
img[0:logoHeight, 0:logoWidth] *= 1 - alpha
img[0:logoHeight, 0:logoWidth] += logo * alpha
cv2.imwrite('addLogo.jpg', img)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment