Extracting Signatures from Images using OpenCV

Viewed 22

I have a task of extracting signatures from Images as images (some images has multiple signatures).

I saw many online repositories for extracting the signatures, but nothing seems to work. I would like to know any available approaches for extracting signature or any pythonic way of implementing it. I thought of applying bounding boxes to all the signatures present in the image, but unable to write the logic for it. I would really like some inputs. It will be really useful

So far I have written a basic one. But it did not get the job done.

import cv2 
import numpy as np
img = cv2.imread('input.png')
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
img=cv2.bitwise_not(img) #negate image

#color definition
blue_upper = np.array([130,255,255])
blue_lower = np.array([115,0,0])

#blue color mask (sort of thresholding, actually segmentation)
mask = cv2.inRange(hsv, blue_lower, blue_upper)
kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (20,20))
finger=cv2.morphologyEx(mask, cv2.MORPH_OPEN, kernel)

mask2=cv2.morphologyEx(finger, cv2.MORPH_DILATE, kernel)
signature=cv2.compare(mask2, mask, cv2.CMP_LT)
signature=cv2.morphologyEx(signature, cv2.MORPH_DILATE, kernel)

signature=cv2.bitwise_and(img, img, mask=signature)
signature=cv2.bitwise_not(signature)

cv2.imwrite('signature.png',signature)

Thank you in advance! cheers!

0 Answers
Related