Created
April 2, 2020 07:08
-
-
Save IngIeoAndSpare/f7d8e7275c0b87b1287d8e2d8f5b42c5 to your computer and use it in GitHub Desktop.
background add alpha layer and convert png 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
import cv2 | |
def transBg(self, img): | |
tmp = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
_,alpha = cv2.threshold(tmp,0,255,cv2.THRESH_BINARY) | |
b, g, r = cv2.split(img) | |
rgba = [b,g,r, alpha] | |
dst = cv2.merge(rgba,4) | |
return dst |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment