-
Notifications
You must be signed in to change notification settings - Fork 26
/
signature.py
31 lines (26 loc) · 973 Bytes
/
signature.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import cv2
from skimage.metrics import structural_similarity as ssim
# TODO add contour detection for enhanced accuracy
def match(path1, path2):
# read the images
img1 = cv2.imread(path1)
img2 = cv2.imread(path2)
# turn images to grayscale
img1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
# resize images for comparison
img1 = cv2.resize(img1, (300, 300))
img2 = cv2.resize(img2, (300, 300))
# display both images
cv2.imshow("One", img1)
cv2.imshow("Two", img2)
cv2.waitKey(0)
cv2.destroyAllWindows()
similarity_value = "{:.2f}".format(ssim(img1, img2)*100)
# print("answer is ", float(similarity_value),
# "type=", type(similarity_value))
return float(similarity_value)
# ans = match("D:\\Code\\Git stuff\\Signature-Matching\\assets\\1.png",
# "D:\\Code\\Git stuff\\Signature-Matching\\assets\\3.png")
# print(ans)
# print(type(ans))