Created
August 24, 2022 20:24
-
-
Save welmends/ac36952a88fde4bc33257e222fdcb56b to your computer and use it in GitHub Desktop.
Signature Background Removal with OpenCV
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 as cv | |
import numpy as np | |
class SignatureBackgroundRemoval: | |
def process_signature(self, img): | |
img = cv.GaussianBlur(img,(5,5),0) | |
img = cv.cvtColor(img, cv.COLOR_BGR2GRAY) | |
ret, img = cv.threshold(img,0,255,cv.THRESH_BINARY+cv.THRESH_OTSU) | |
alpha = np.ones(img.shape, dtype=img.dtype)*255 | |
out = cv.merge((img, img, img, alpha)) | |
out[np.all(out == [255, 255, 255, 255], axis=2)] = [0, 0, 0, 0] | |
return out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment