forked from MahmoudHigazy/Roz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roz_gui.py
210 lines (164 loc) · 6.12 KB
/
roz_gui.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import tkinter as tk
from PIL import ImageTk, Image
import tkFileDialog as filedialog
from roz import *
LARGE_FONT = ("Verdana", 12)
dataset_path = ''
img_path = ''
preds = []
w = None
def browse_image(event):
global img_path
img_path = filedialog.askopenfilename(filetypes=(("All files", "*.type"), ("All files", "*")))
img = Image.open(img_path)
# img = img.resize((700, 700))
img.show()
def Browse_Folder(event):
# Allow user to select a directory and store it in global var
# called folder_path
global dataset_path
dataset_path = filedialog.askdirectory()
print dataset_path
def extract_embeddings_function(event):
print('extract_embeddings_button clicked')
print(dataset_path)
preprocess_dataset(dataset_path + '/')
save_aligned_images(dataset_path)
get_embeddings('./aligned_images')
def recognize_students_function(event):
print('recognize_students_button clicked')
global preds
X = np.load('X.npy')
y = np.load('y.npy')
preprocess_image(img_path)
preds = test(img_path, X, y)
def take_attendence_function(event):
print('take_attendence_button clicked')
week_number = int(app.frames[StartPage].textbox5.get())
RecordAttendance('Attendance.xlsx', 'section 1', week_number, preds)
def MyKernel():
global CroppedImage
AttendanceDone=False
CroppedImage = []
cap = cv2.VideoCapture(0)
MyTemplate = cap.read()
FrameNumber = 0
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
xhTemp = 0
yhTemp = 0
NFrames = 9
Counter=0
while (True):
ret, frame = cap.read()
Image = frame
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face = detect_image(frame, False)
xh, yh, wh, hh = 0, 0, 0, 0
for f in face:
xh = f.left()
yh = f.top()
wh = f.right()
hh = f.bottom()
Image = frame
Image = cv2.rectangle(Image, (xh, yh), (wh, hh), (255, 0, 0), 2)
if abs(xh - xhTemp) < 20:
Counter = Counter + 1
else:
Counter = 0
if Counter == NFrames:
# AttendanceDone=True
ret, frame = cap.read()
cv2.imwrite('test.jpg', frame)
cap.release()
cv2.destroyAllWindows()
return frame
xhTemp = xh
yhTemp = yh
cv2.imshow('frame', Image)
if cv2.waitKey(1) & 0xFF == ord('q'):
print{FrameNumber}
break
FrameNumber = FrameNumber + 1
cap.release()
cv2.destroyAllWindows()
# cv2.imshow('frame', CroppedImage)
# cv2.waitKey(0)
return None
def video(event):
MyKernel()
X = np.load('X.npy')
y = np.load('y.npy')
preds = test('test.jpg', X, y)
print('done')
week_number = int(app.frames[StartPage].textbox5.get())
RecordAttendance('Attendance.xlsx', 'section 1', week_number, preds)
class SeaofBTCapp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, MainPage):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Start Page", font=LARGE_FONT)
label.pack(pady=10, padx=10)
tk.Label(self, text="TA name :", font=LARGE_FONT).pack()
textbox1 = tk.Entry(self)
textbox1.pack()
tk.Label(self, text="Year number :", font=LARGE_FONT).pack()
textbox2 = tk.Entry(self)
textbox2.pack()
tk.Label(self, text="Course name :", font=LARGE_FONT).pack()
textbox3 = tk.Entry(self)
textbox3.pack()
tk.Label(self, text="Section number :", font=LARGE_FONT).pack()
textbox4 = tk.Entry(self)
textbox4.pack()
tk.Label(self, text="Week number :", font=LARGE_FONT).pack()
self.textbox5 = tk.Entry(self)
self.textbox5.pack()
start_button = tk.Button(self, text='Start', command=lambda :controller.show_frame(MainPage))
start_button.pack()
class MainPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
# Buttons
browse_dataset_button = tk.Button(self, text='Browse Dataset')
extract_embeddings_button = tk.Button(self, text='Extract Embeddings')
camera_button = tk.Button(self, text='Take attendance by camera')
browse_image_button = tk.Button(self, text='Browse Image')
recognize_students_button = tk.Button(self, text='Recognize the students')
take_attendence_button = tk.Button(self, text='take the attendance')
# Buttons Positions
browse_dataset_button.pack()
extract_embeddings_button.pack()
camera_button.pack()
browse_image_button.pack()
recognize_students_button.pack()
take_attendence_button.pack()
browse_dataset_button.bind("<Button-1>", Browse_Folder)
extract_embeddings_button.bind("<Button-1>", extract_embeddings_function)
camera_button.bind("<Button-1>", video)
browse_image_button.bind("<Button-1>", browse_image)
recognize_students_button.bind("<Button-1>", recognize_students_function)
take_attendence_button.bind("<Button-1>", take_attendence_function)
'''img = ImageTk.PhotoImage(Image.open("Roz.jpg"))
panel = tk.Label(self, image=img)
panel.pack(side="bottom", fill="both", expand="yes")'''
app = SeaofBTCapp()
app.title('Roz')
img = ImageTk.PhotoImage(Image.open("Roz.jpg"))
panel = tk.Label(app, image=img)
panel.pack(side="bottom", fill="both", expand="yes")
app.mainloop()