Created
January 24, 2016 10:56
-
-
Save PeaceAndHiLight/89b0211ef2eb0710a581 to your computer and use it in GitHub Desktop.
Add png Image On Jpeg Image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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