-
Notifications
You must be signed in to change notification settings - Fork 0
/
automaticAttedance.py
281 lines (264 loc) · 9.31 KB
/
automaticAttedance.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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
import tkinter as tk
from tkinter import *
import os, cv2
import shutil
import csv
import numpy as np
from PIL import ImageTk, Image
import pandas as pd
import datetime
import time
import tkinter.ttk as tkk
import tkinter.font as font
haarcasecade_path = "haarcascade_frontalface_default.xml"
trainimagelabel_path = (
"TrainingImageLabel\\Trainner.yml"
)
trainimage_path = "TrainingImage"
studentdetail_path = (
"StudentDetails\\studentdetails.csv"
)
attendance_path = "Attendance"
# for choose subject and fill attendance
def subjectChoose():
def FillAttendance():
sub = tx.get()
now = time.time()
future = now + 20
print(now)
print(future)
if sub == "":
t = "Please enter the subject name!!!"
#text_to_speech(t)
else:
try:
recognizer = cv2.face.LBPHFaceRecognizer_create()
try:
recognizer.read(trainimagelabel_path)
except:
e = "Model not found,please train model"
Notifica.configure(
text=e,
bg="black",
fg="yellow",
width=33,
font=("times", 15, "bold"),
)
Notifica.place(x=20, y=250)
#text_to_speech(e)
facecasCade = cv2.CascadeClassifier(haarcasecade_path)
df = pd.read_csv(studentdetail_path)
cam = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX
col_names = ["Enrollment", "Name"]
attendance = pd.DataFrame(columns=col_names)
while True:
___, im = cam.read()
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
faces = facecasCade.detectMultiScale(gray, 1.2, 5)
for (x, y, w, h) in faces:
global Id
Id, conf = recognizer.predict(gray[y : y + h, x : x + w])
if conf < 70:
print(conf)
global Subject
global aa
global date
global timeStamp
Subject = tx.get()
ts = time.time()
date = datetime.datetime.fromtimestamp(ts).strftime(
"%Y-%m-%d"
)
timeStamp = datetime.datetime.fromtimestamp(ts).strftime(
"%H:%M:%S"
)
aa = df.loc[df["Enrollment"] == Id]["Name"].values
global tt
tt = str(Id) + "-" + aa
# En='1604501160'+str(Id)
attendance.loc[len(attendance)] = [
Id,
aa,
]
cv2.rectangle(im, (x, y), (x + w, y + h), (0, 260, 0), 4)
cv2.putText(
im, str(tt), (x + h, y), font, 1, (255, 255, 0,), 4
)
else:
Id = "Unknown"
tt = str(Id)
cv2.rectangle(im, (x, y), (x + w, y + h), (0, 25, 255), 7)
cv2.putText(
im, str(tt), (x + h, y), font, 1, (0, 25, 255), 4
)
if time.time() > future:
break
attendance = attendance.drop_duplicates(
["Enrollment"], keep="first"
)
cv2.imshow("Filling Attendance...", im)
key = cv2.waitKey(30) & 0xFF
if key == 27:
break
ts = time.time()
print(aa)
# attendance["date"] = date
# attendance["Attendance"] = "P"
attendance[date] = 1
date = datetime.datetime.fromtimestamp(ts).strftime("%Y-%m-%d")
timeStamp = datetime.datetime.fromtimestamp(ts).strftime("%H:%M:%S")
Hour, Minute, Second = timeStamp.split(":")
#fileName = "Attendance/" + Subject + ".csv"
path = os.path.join(attendance_path, Subject)
fileName = (
f"{path}//"
+ Subject
+ "_"
+ date
+ "_"
+ Hour
+ "-"
+ Minute
+ "-"
+ Second
+ ".csv"
)
attendance = attendance.drop_duplicates(["Enrollment"], keep="first")
print(attendance)
attendance.to_csv(fileName, index=False)
m = "Attendance Filled Successfully of " + Subject
Notifica.configure(
text=m,
bg="black",
fg="yellow",
width=33,
relief=RIDGE,
bd=5,
font=("times", 15, "bold"),
)
#text_to_speech(m)
Notifica.place(x=20, y=250)
cam.release()
cv2.destroyAllWindows()
import csv
import tkinter
root = tkinter.Tk()
root.title("Attendance of " + subject)
root.configure(background="black")
cs = os.path.join(path, fileName)
print(cs)
with open(cs, newline="") as file:
reader = csv.reader(file)
r = 0
for col in reader:
c = 0
for row in col:
label = tkinter.Label(
root,
width=10,
height=1,
fg="yellow",
font=("times", 15, " bold "),
bg="black",
text=row,
relief=tkinter.RIDGE,
)
label.grid(row=r, column=c)
c += 1
r += 1
root.mainloop()
print(attendance)
except:
f = "No Face found for attendance"
#text_to_speech(f)
cv2.destroyAllWindows()
###windo is frame for subject chooser
subject = Tk()
# windo.iconbitmap("AMS.ico")
subject.title("Subject...")
subject.geometry("580x320")
subject.resizable(0, 0)
subject.configure(background="black")
# subject_logo = Image.open("UI_Image/0004.png")
# subject_logo = subject_logo.resize((50, 47), Image.LANCZOS)
# subject_logo1 = ImageTk.PhotoImage(subject_logo)
titl = tk.Label(subject, bg="black", relief=RIDGE, bd=10, font=("arial", 30))
titl.pack(fill=X)
# l1 = tk.Label(subject, image=subject_logo1, bg="black",)
# l1.place(x=100, y=10)
titl = tk.Label(
subject,
text="Enter the Subject Name",
bg="black",
fg="green",
font=("arial", 25),
)
titl.place(x=160, y=12)
Notifica = tk.Label(
subject,
text="Attendance filled Successfully",
bg="yellow",
fg="black",
width=33,
height=2,
font=("times", 15, "bold"),
)
def Attf():
sub = tx.get()
if sub == "":
t = "Please enter the subject name!!!"
#text_to_speech(t)
else:
os.startfile(
f"Attendance\\{sub}"
)
attf = tk.Button(
subject,
text="Check Sheets",
command=Attf,
bd=7,
font=("times new roman", 15),
bg="black",
fg="yellow",
height=2,
width=10,
relief=RIDGE,
)
attf.place(x=360, y=170)
sub = tk.Label(
subject,
text="Enter Subject",
width=10,
height=2,
bg="black",
fg="yellow",
bd=5,
relief=RIDGE,
font=("times new roman", 15),
)
sub.place(x=50, y=100)
tx = tk.Entry(
subject,
width=15,
bd=5,
bg="black",
fg="yellow",
relief=RIDGE,
font=("times", 30, "bold"),
)
tx.place(x=190, y=100)
fill_a = tk.Button(
subject,
text="Fill Attendance",
command=FillAttendance,
bd=7,
font=("times new roman", 15),
bg="black",
fg="yellow",
height=2,
width=12,
relief=RIDGE,
)
fill_a.place(x=195, y=170)
subject.mainloop()