Skip to content

Instantly share code, notes, and snippets.

@IngIeoAndSpare
Created April 2, 2020 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IngIeoAndSpare/f7d8e7275c0b87b1287d8e2d8f5b42c5 to your computer and use it in GitHub Desktop.
Save IngIeoAndSpare/f7d8e7275c0b87b1287d8e2d8f5b42c5 to your computer and use it in GitHub Desktop.
background add alpha layer and convert png image
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