-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.py
129 lines (103 loc) · 3.94 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter import messagebox
import os
import cv2
from numpy import result_type
from signature import match
# Mach Threshold
THRESHOLD = 85
def browsefunc(ent):
filename = askopenfilename(filetypes=([
("image", ".jpeg"),
("image", ".png"),
("image", ".jpg"),
]))
ent.delete(0, tk.END)
ent.insert(tk.END, filename) # add this
def capture_image_from_cam_into_temp(sign=1):
cam = cv2.VideoCapture(0, cv2.CAP_DSHOW)
cv2.namedWindow("test")
# img_counter = 0
while True:
ret, frame = cam.read()
if not ret:
print("failed to grab frame")
break
cv2.imshow("test", frame)
k = cv2.waitKey(1)
if k % 256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
elif k % 256 == 32:
# SPACE pressed
if not os.path.isdir('temp'):
os.mkdir('temp', mode=0o777) # make sure the directory exists
# img_name = "./temp/opencv_frame_{}.png".format(img_counter)
if(sign == 1):
img_name = "./temp/test_img1.png"
else:
img_name = "./temp/test_img2.png"
print('imwrite=', cv2.imwrite(filename=img_name, img=frame))
print("{} written!".format(img_name))
# img_counter += 1
cam.release()
cv2.destroyAllWindows()
return True
def captureImage(ent, sign=1):
if(sign == 1):
filename = os.getcwd()+'\\temp\\test_img1.png'
else:
filename = os.getcwd()+'\\temp\\test_img2.png'
# messagebox.showinfo(
# 'SUCCESS!!!', 'Press Space Bar to click picture and ESC to exit')
res = None
res = messagebox.askquestion(
'Click Picture', 'Press Space Bar to click picture and ESC to exit')
if res == 'yes':
capture_image_from_cam_into_temp(sign=sign)
ent.delete(0, tk.END)
ent.insert(tk.END, filename)
return True
def checkSimilarity(window, path1, path2):
result = match(path1=path1, path2=path2)
if(result <= THRESHOLD):
messagebox.showerror("Failure: Signatures Do Not Match",
"Signatures are "+str(result)+f" % similar!!")
pass
else:
messagebox.showinfo("Success: Signatures Match",
"Signatures are "+str(result)+f" % similar!!")
return True
root = tk.Tk()
root.title("Signature Matching")
root.geometry("500x700") # 300x200
uname_label = tk.Label(root, text="Compare Two Signatures:", font=10)
uname_label.place(x=90, y=50)
img1_message = tk.Label(root, text="Signature 1", font=10)
img1_message.place(x=10, y=120)
image1_path_entry = tk.Entry(root, font=10)
image1_path_entry.place(x=150, y=120)
img1_capture_button = tk.Button(
root, text="Capture", font=10, command=lambda: captureImage(ent=image1_path_entry, sign=1))
img1_capture_button.place(x=400, y=90)
img1_browse_button = tk.Button(
root, text="Browse", font=10, command=lambda: browsefunc(ent=image1_path_entry))
img1_browse_button.place(x=400, y=140)
image2_path_entry = tk.Entry(root, font=10)
image2_path_entry.place(x=150, y=240)
img2_message = tk.Label(root, text="Signature 2", font=10)
img2_message.place(x=10, y=250)
img2_capture_button = tk.Button(
root, text="Capture", font=10, command=lambda: captureImage(ent=image2_path_entry, sign=2))
img2_capture_button.place(x=400, y=210)
img2_browse_button = tk.Button(
root, text="Browse", font=10, command=lambda: browsefunc(ent=image2_path_entry))
img2_browse_button.place(x=400, y=260)
compare_button = tk.Button(
root, text="Compare", font=10, command=lambda: checkSimilarity(window=root,
path1=image1_path_entry.get(),
path2=image2_path_entry.get(),))
compare_button.place(x=200, y=320)
root.mainloop()