-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain-app.py
55 lines (44 loc) · 1.86 KB
/
main-app.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import sys
import argparse
import cv2
from matplotlib import pyplot as plt
from Libraries.ExtractKeypoints.ExtractKeypoints import extractKeypoints
def main(args):
print('----|| INIT MODULE ||----')
img1 = cv2.imread(args.image, cv2.IMREAD_GRAYSCALE)
kp1, des1 = extractKeypoints(img1)
img2 = cv2.imread(args.ref_image, cv2.IMREAD_GRAYSCALE)
kp2, des2 = extractKeypoints(img2)
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = sorted(bf.match(des1, des2), key=lambda match: match.distance)
img4 = cv2.drawKeypoints(img1, kp1, outImage=None)
img5 = cv2.drawKeypoints(img2, kp2, outImage=None)
if args.visual:
f, axarr = plt.subplots(1, 2)
axarr[0].imshow(img4)
axarr[1].imshow(img5)
plt.show()
img3 = cv2.drawMatches(img1, kp1, img2, kp2, matches, flags=2, outImg=None)
plt.imshow(img3)
plt.show()
score = 0
for match in matches:
score += match.distance
if score / len(matches) < args.thres:
print("RESULT: Signature match with score = {}".format(100-(score / len(matches))))
else:
print("RESULT: Signature does not match.")
print('----|| MODULE ENDED ||----')
def setup(argv):
parser = argparse.ArgumentParser()
parser.add_argument('--image', help='Provide signature image path needs to be verified', type=str, default='Data/signature.jpg')
parser.add_argument('--ref_image', help='Provide reference signature image path needs to be verified', type=str, default='Data/ref-signature.jpg')
parser.add_argument('--thres', help='Signature matching threshold', type=int, default=20)
parser.add_argument('--visual', help='Visulisation of result', type=bool, default=True)
return parser.parse_args(argv)
if __name__ == '__main__':
'''
Configuration
'''
arguments = setup(sys.argv[1:])
main(args=arguments)