└── AMS_Run.py /AMS_Run.py: -------------------------------------------------------------------------------- 1 | import tkinter as tk 2 | from tkinter import * 3 | import cv2 4 | import csv 5 | import os 6 | import numpy as np 7 | from PIL import Image,ImageTk 8 | import pandas as pd 9 | import datetime 10 | import time 11 | 12 | #####Window is our Main frame of system 13 | window = tk.Tk() 14 | window.title("FAMS-Face Recognition Based Attendance Management System") 15 | 16 | window.geometry('1280x720') 17 | window.configure(background='snow') 18 | 19 | ####GUI for manually fill attendance 20 | 21 | def manually_fill(): 22 | global sb 23 | sb = tk.Tk() 24 | sb.iconbitmap('AMS.ico') 25 | sb.title("Enter subject name...") 26 | sb.geometry('580x320') 27 | sb.configure(background='snow') 28 | 29 | def err_screen_for_subject(): 30 | 31 | def ec_delete(): 32 | ec.destroy() 33 | global ec 34 | ec = tk.Tk() 35 | ec.geometry('300x100') 36 | ec.iconbitmap('AMS.ico') 37 | ec.title('Warning!!') 38 | ec.configure(background='snow') 39 | Label(ec, text='Please enter your subject name!!!', fg='red', bg='white', font=('times', 16, ' bold ')).pack() 40 | Button(ec, text='OK', command=ec_delete, fg="black", bg="lawn green", width=9, height=1, activebackground="Red", 41 | font=('times', 15, ' bold ')).place(x=90, y=50) 42 | 43 | def fill_attendance(): 44 | ts = time.time() 45 | Date = datetime.datetime.fromtimestamp(ts).strftime('%Y_%m_%d') 46 | timeStamp = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S') 47 | Time = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S') 48 | Hour, Minute, Second = timeStamp.split(":") 49 | ####Creating csv of attendance 50 | 51 | ##Create table for Attendance 52 | date_for_DB = datetime.datetime.fromtimestamp(ts).strftime('%Y_%m_%d') 53 | global subb 54 | subb=SUB_ENTRY.get() 55 | DB_table_name = str(subb + "_" + Date + "_Time_" + Hour + "_" + Minute + "_" + Second) 56 | 57 | import pymysql.connections 58 | 59 | ###Connect to the database 60 | try: 61 | global cursor 62 | connection = pymysql.connect(host='localhost', user='root', password='', db='manually_fill_attendance') 63 | cursor = connection.cursor() 64 | except Exception as e: 65 | print(e) 66 | 67 | sql = "CREATE TABLE " + DB_table_name + """ 68 | (ID INT NOT NULL AUTO_INCREMENT, 69 | ENROLLMENT varchar(100) NOT NULL, 70 | NAME VARCHAR(50) NOT NULL, 71 | DATE VARCHAR(20) NOT NULL, 72 | TIME VARCHAR(20) NOT NULL, 73 | PRIMARY KEY (ID) 74 | ); 75 | """ 76 | 77 | 78 | try: 79 | cursor.execute(sql) #for create a table 80 | connection.commit() 81 | except Exception as ex: 82 | print(ex) # 83 | 84 | if subb=='': 85 | err_screen_for_subject() 86 | else: 87 | sb.destroy() 88 | MFW = tk.Tk() 89 | MFW.iconbitmap('AMS.ico') 90 | MFW.title("Manually attendance of "+ str(subb)) 91 | MFW.geometry('880x470') 92 | MFW.configure(background='snow') 93 | 94 | def del_errsc2(): 95 | errsc2.destroy() 96 | 97 | def err_screen1(): 98 | global errsc2 99 | errsc2 = tk.Tk() 100 | errsc2.geometry('330x100') 101 | errsc2.iconbitmap('AMS.ico') 102 | errsc2.title('Warning!!') 103 | errsc2.configure(background='snow') 104 | Label(errsc2, text='Please enter Student & Enrollment!!!', fg='red', bg='white', 105 | font=('times', 16, ' bold ')).pack() 106 | Button(errsc2, text='OK', command=del_errsc2, fg="black", bg="lawn green", width=9, height=1, 107 | activebackground="Red", font=('times', 15, ' bold ')).place(x=90, y=50) 108 | 109 | def testVal(inStr, acttyp): 110 | if acttyp == '1': # insert 111 | if not inStr.isdigit(): 112 | return False 113 | return True 114 | 115 | ENR = tk.Label(MFW, text="Enter Enrollment", width=15, height=2, fg="white", bg="blue2", 116 | font=('times', 15, ' bold ')) 117 | ENR.place(x=30, y=100) 118 | 119 | STU_NAME = tk.Label(MFW, text="Enter Student name", width=15, height=2, fg="white", bg="blue2", 120 | font=('times', 15, ' bold ')) 121 | STU_NAME.place(x=30, y=200) 122 | 123 | global ENR_ENTRY 124 | ENR_ENTRY = tk.Entry(MFW, width=20,validate='key', bg="yellow", fg="red", font=('times', 23, ' bold ')) 125 | ENR_ENTRY['validatecommand'] = (ENR_ENTRY.register(testVal), '%P', '%d') 126 | ENR_ENTRY.place(x=290, y=105) 127 | 128 | def remove_enr(): 129 | ENR_ENTRY.delete(first=0, last=22) 130 | 131 | STUDENT_ENTRY = tk.Entry(MFW, width=20, bg="yellow", fg="red", font=('times', 23, ' bold ')) 132 | STUDENT_ENTRY.place(x=290, y=205) 133 | 134 | def remove_student(): 135 | STUDENT_ENTRY.delete(first=0, last=22) 136 | 137 | ####get important variable 138 | def enter_data_DB(): 139 | ENROLLMENT = ENR_ENTRY.get() 140 | STUDENT = STUDENT_ENTRY.get() 141 | if ENROLLMENT=='': 142 | err_screen1() 143 | elif STUDENT=='': 144 | err_screen1() 145 | else: 146 | time = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S') 147 | Hour, Minute, Second = time.split(":") 148 | Insert_data = "INSERT INTO " + DB_table_name + " (ID,ENROLLMENT,NAME,DATE,TIME) VALUES (0, %s, %s, %s,%s)" 149 | VALUES = (str(ENROLLMENT), str(STUDENT), str(Date), str(time)) 150 | try: 151 | cursor.execute(Insert_data, VALUES) 152 | connection.commit() 153 | except Exception as e: 154 | print(e) 155 | ENR_ENTRY.delete(first=0, last=22) 156 | STUDENT_ENTRY.delete(first=0, last=22) 157 | 158 | def create_csv(): 159 | import csv 160 | cursor.execute("select * from " + DB_table_name + ";") 161 | connection.commit() 162 | csv_name='C:/Python36/Attendace_system_major_project/Attendance'+DB_table_name+'.csv' 163 | with open(csv_name, "w") as csv_file: 164 | csv_writer = csv.writer(csv_file) 165 | csv_writer.writerow([i[0] for i in cursor.description]) # write headers 166 | csv_writer.writerows(cursor) 167 | O="CSV created Successfully" 168 | Notifi.configure(text=O, bg="Green", fg="white", width=33, font=('times', 19, 'bold')) 169 | Notifi.place(x=180, y=380) 170 | import csv 171 | import tkinter 172 | root = tkinter.Tk() 173 | root.title("Attendance of " + subb) 174 | root.configure(background='snow') 175 | with open(csv_name, newline="") as file: 176 | reader = csv.reader(file) 177 | r = 0 178 | 179 | for col in reader: 180 | c = 0 181 | for row in col: 182 | # i've added some styling 183 | label = tkinter.Label(root, width=13, height=1, fg="black", font=('times', 13, ' bold '), 184 | bg="lawn green", text=row, relief=tkinter.RIDGE) 185 | label.grid(row=r, column=c) 186 | c += 1 187 | r += 1 188 | root.mainloop() 189 | 190 | Notifi = tk.Label(MFW, text="CSV created Successfully", bg="Green", fg="white", width=33, 191 | height=2, font=('times', 19, 'bold')) 192 | 193 | 194 | c1ear_enroll = tk.Button(MFW, text="Clear", command=remove_enr, fg="black", bg="deep pink", width=10, 195 | height=1, 196 | activebackground="Red", font=('times', 15, ' bold ')) 197 | c1ear_enroll.place(x=690, y=100) 198 | 199 | c1ear_student = tk.Button(MFW, text="Clear", command=remove_student, fg="black", bg="deep pink", width=10, 200 | height=1, 201 | activebackground="Red", font=('times', 15, ' bold ')) 202 | c1ear_student.place(x=690, y=200) 203 | 204 | DATA_SUB = tk.Button(MFW, text="Enter Data",command=enter_data_DB, fg="black", bg="lime green", width=20, 205 | height=2, 206 | activebackground="Red", font=('times', 15, ' bold ')) 207 | DATA_SUB.place(x=170, y=300) 208 | 209 | MAKE_CSV = tk.Button(MFW, text="Convert to CSV",command=create_csv, fg="black", bg="red", width=20, 210 | height=2, 211 | activebackground="Red", font=('times', 15, ' bold ')) 212 | MAKE_CSV.place(x=570, y=300) 213 | 214 | def attf(): 215 | import subprocess 216 | subprocess.Popen(r'explorer /select,"C:/Python36/Attendace_system_major_project/Attendance/Manually Attendance/-------Check atttendance-------"') 217 | 218 | attf = tk.Button(MFW, text="Check Sheets",command=attf,fg="black" ,bg="lawn green" ,width=12 ,height=1 ,activebackground = "Red" ,font=('times', 14, ' bold ')) 219 | attf.place(x=730, y=410) 220 | 221 | MFW.mainloop() 222 | 223 | 224 | SUB = tk.Label(sb, text="Enter Subject", width=15, height=2, fg="white", bg="blue2", font=('times', 15, ' bold ')) 225 | SUB.place(x=30, y=100) 226 | 227 | global SUB_ENTRY 228 | 229 | SUB_ENTRY = tk.Entry(sb, width=20, bg="yellow", fg="red", font=('times', 23, ' bold ')) 230 | SUB_ENTRY.place(x=250, y=105) 231 | 232 | fill_manual_attendance = tk.Button(sb, text="Fill Attendance",command=fill_attendance, fg="white", bg="deep pink", width=20, height=2, 233 | activebackground="Red", font=('times', 15, ' bold ')) 234 | fill_manual_attendance.place(x=250, y=160) 235 | sb.mainloop() 236 | 237 | ##For clear textbox 238 | def clear(): 239 | txt.delete(first=0, last=22) 240 | 241 | def clear1(): 242 | txt2.delete(first=0, last=22) 243 | def del_sc1(): 244 | sc1.destroy() 245 | def err_screen(): 246 | global sc1 247 | sc1 = tk.Tk() 248 | sc1.geometry('300x100') 249 | sc1.iconbitmap('AMS.ico') 250 | sc1.title('Warning!!') 251 | sc1.configure(background='snow') 252 | Label(sc1,text='Enrollment & Name required!!!',fg='red',bg='white',font=('times', 16, ' bold ')).pack() 253 | Button(sc1,text='OK',command=del_sc1,fg="black" ,bg="lawn green" ,width=9 ,height=1, activebackground = "Red" ,font=('times', 15, ' bold ')).place(x=90,y= 50) 254 | 255 | ##Error screen2 256 | def del_sc2(): 257 | sc2.destroy() 258 | def err_screen1(): 259 | global sc2 260 | sc2 = tk.Tk() 261 | sc2.geometry('300x100') 262 | sc2.iconbitmap('AMS.ico') 263 | sc2.title('Warning!!') 264 | sc2.configure(background='snow') 265 | Label(sc2,text='Please enter your subject name!!!',fg='red',bg='white',font=('times', 16, ' bold ')).pack() 266 | Button(sc2,text='OK',command=del_sc2,fg="black" ,bg="lawn green" ,width=9 ,height=1, activebackground = "Red" ,font=('times', 15, ' bold ')).place(x=90,y= 50) 267 | 268 | ###For take images for datasets 269 | def take_img(): 270 | l1 = txt.get() 271 | l2 = txt2.get() 272 | if l1 == '': 273 | err_screen() 274 | elif l2 == '': 275 | err_screen() 276 | else: 277 | try: 278 | cam = cv2.VideoCapture(0) 279 | detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 280 | Enrollment = txt.get() 281 | Name = txt2.get() 282 | sampleNum = 0 283 | while (True): 284 | ret, img = cam.read() 285 | gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 286 | faces = detector.detectMultiScale(gray, 1.3, 5) 287 | for (x, y, w, h) in faces: 288 | cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2) 289 | # incrementing sample number 290 | sampleNum = sampleNum + 1 291 | # saving the captured face in the dataset folder 292 | cv2.imwrite("TrainingImage/ " + Name + "." + Enrollment + '.' + str(sampleNum) + ".jpg", 293 | gray[y:y + h, x:x + w]) 294 | cv2.imshow('Frame', img) 295 | # wait for 100 miliseconds 296 | if cv2.waitKey(1) & 0xFF == ord('q'): 297 | break 298 | # break if the sample number is morethan 100 299 | elif sampleNum > 70: 300 | break 301 | cam.release() 302 | cv2.destroyAllWindows() 303 | ts = time.time() 304 | Date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d') 305 | Time = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S') 306 | row = [Enrollment, Name, Date, Time] 307 | with open('StudentDetails\StudentDetails.csv', 'a+') as csvFile: 308 | writer = csv.writer(csvFile, delimiter=',') 309 | writer.writerow(row) 310 | csvFile.close() 311 | res = "Images Saved for Enrollment : " + Enrollment + " Name : " + Name 312 | Notification.configure(text=res, bg="SpringGreen3", width=50, font=('times', 18, 'bold')) 313 | Notification.place(x=250, y=400) 314 | except FileExistsError as F: 315 | f = 'Student Data already exists' 316 | Notification.configure(text=f, bg="Red", width=21) 317 | Notification.place(x=450, y=400) 318 | 319 | 320 | ###for choose subject and fill attendance 321 | def subjectchoose(): 322 | def Fillattendances(): 323 | sub=tx.get() 324 | now = time.time() ###For calculate seconds of video 325 | future = now + 20 326 | if time.time() < future: 327 | if sub == '': 328 | err_screen1() 329 | else: 330 | recognizer = cv2.face.LBPHFaceRecognizer_create() # cv2.createLBPHFaceRecognizer() #taking image 331 | try: 332 | recognizer.read("TrainingImageLabel\Trainner.yml") 333 | except: 334 | e = 'Model not found,Please train model' 335 | Notifica.configure(text=e, bg="red", fg="black", width=33, font=('times', 15, 'bold')) 336 | Notifica.place(x=20, y=250) 337 | 338 | harcascadePath = "haarcascade_frontalface_default.xml" 339 | faceCascade = cv2.CascadeClassifier(harcascadePath) 340 | df = pd.read_csv("StudentDetails\StudentDetails.csv") 341 | cam = cv2.VideoCapture(0) 342 | font = cv2.FONT_HERSHEY_SIMPLEX 343 | col_names = ['Enrollment', 'Name', 'Date', 'Time'] 344 | attendance = pd.DataFrame(columns=col_names) 345 | while True: 346 | ret, im = cam.read() 347 | gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) 348 | faces = faceCascade.detectMultiScale(gray, 1.2, 5) 349 | for (x, y, w, h) in faces: 350 | global Id 351 | 352 | Id, conf = recognizer.predict(gray[y:y + h, x:x + w]) 353 | if (conf <70): 354 | print(conf) 355 | global Subject 356 | global aa 357 | global date 358 | global timeStamp 359 | Subject = tx.get() 360 | ts = time.time() 361 | date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d') 362 | timeStamp = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S') 363 | aa = df.loc[df['Enrollment'] == Id]['Name'].values 364 | global tt 365 | tt = str(Id) + "-" + aa 366 | En = '15624031' + str(Id) 367 | attendance.loc[len(attendance)] = [Id, aa, date, timeStamp] 368 | cv2.rectangle(im, (x, y), (x + w, y + h), (0, 260, 0), 7) 369 | cv2.putText(im, str(tt), (x + h, y), font, 1, (255, 255, 0,), 4) 370 | 371 | else: 372 | Id = 'Unknown' 373 | tt = str(Id) 374 | cv2.rectangle(im, (x, y), (x + w, y + h), (0, 25, 255), 7) 375 | cv2.putText(im, str(tt), (x + h, y), font, 1, (0, 25, 255), 4) 376 | if time.time() > future: 377 | break 378 | 379 | attendance = attendance.drop_duplicates(['Enrollment'], keep='first') 380 | cv2.imshow('Filling attedance..', im) 381 | key = cv2.waitKey(30) & 0xff 382 | if key == 27: 383 | break 384 | 385 | ts = time.time() 386 | date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d') 387 | timeStamp = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S') 388 | Hour, Minute, Second = timeStamp.split(":") 389 | fileName = "Attendance/" + Subject + "_" + date + "_" + Hour + "-" + Minute + "-" + Second + ".csv" 390 | attendance = attendance.drop_duplicates(['Enrollment'], keep='first') 391 | print(attendance) 392 | attendance.to_csv(fileName, index=False) 393 | 394 | ##Create table for Attendance 395 | date_for_DB = datetime.datetime.fromtimestamp(ts).strftime('%Y_%m_%d') 396 | DB_Table_name = str( Subject + "_" + date_for_DB + "_Time_" + Hour + "_" + Minute + "_" + Second) 397 | import pymysql.connections 398 | 399 | ###Connect to the database 400 | try: 401 | global cursor 402 | connection = pymysql.connect(host='localhost', user='root', password='', db='Face_reco_fill') 403 | cursor = connection.cursor() 404 | except Exception as e: 405 | print(e) 406 | 407 | sql = "CREATE TABLE " + DB_Table_name + """ 408 | (ID INT NOT NULL AUTO_INCREMENT, 409 | ENROLLMENT varchar(100) NOT NULL, 410 | NAME VARCHAR(50) NOT NULL, 411 | DATE VARCHAR(20) NOT NULL, 412 | TIME VARCHAR(20) NOT NULL, 413 | PRIMARY KEY (ID) 414 | ); 415 | """ 416 | ####Now enter attendance in Database 417 | insert_data = "INSERT INTO " + DB_Table_name + " (ID,ENROLLMENT,NAME,DATE,TIME) VALUES (0, %s, %s, %s,%s)" 418 | VALUES = (str(Id), str(aa), str(date), str(timeStamp)) 419 | try: 420 | cursor.execute(sql) ##for create a table 421 | connection.commit() 422 | cursor.execute(insert_data, VALUES)##For insert data into table 423 | connection.commit() 424 | except Exception as ex: 425 | print(ex) # 426 | 427 | M = 'Attendance filled Successfully' 428 | Notifica.configure(text=M, bg="Green", fg="white", width=33, font=('times', 15, 'bold')) 429 | Notifica.place(x=20, y=250) 430 | 431 | cam.release() 432 | cv2.destroyAllWindows() 433 | 434 | import csv 435 | import tkinter 436 | root = tkinter.Tk() 437 | root.title("Attendance of " + Subject) 438 | root.configure(background='snow') 439 | cs = 'C:/Python36/Attendace_system_major_project/' + fileName 440 | with open(cs, newline="") as file: 441 | reader = csv.reader(file) 442 | r = 0 443 | 444 | for col in reader: 445 | c = 0 446 | for row in col: 447 | # i've added some styling 448 | label = tkinter.Label(root, width=8, height=1, fg="black", font=('times', 15, ' bold '), 449 | bg="lawn green", text=row, relief=tkinter.RIDGE) 450 | label.grid(row=r, column=c) 451 | c += 1 452 | r += 1 453 | root.mainloop() 454 | print(attendance) 455 | 456 | ###windo is frame for subject chooser 457 | windo = tk.Tk() 458 | windo.iconbitmap('AMS.ico') 459 | windo.title("Enter subject name...") 460 | windo.geometry('580x320') 461 | windo.configure(background='snow') 462 | Notifica = tk.Label(windo, text="Attendance filled Successfully", bg="Green", fg="white", width=33, 463 | height=2, font=('times', 15, 'bold')) 464 | 465 | def Attf(): 466 | import subprocess 467 | subprocess.Popen(r'explorer /select,"C:/Python36/Attendace_system_major_project/Attendance/-------Check atttendance-------"') 468 | 469 | attf = tk.Button(windo, text="Check Sheets",command=Attf,fg="black" ,bg="lawn green" ,width=12 ,height=1 ,activebackground = "Red" ,font=('times', 14, ' bold ')) 470 | attf.place(x=430, y=255) 471 | 472 | sub = tk.Label(windo, text="Enter Subject", width=15, height=2, fg="white", bg="blue2", font=('times', 15, ' bold ')) 473 | sub.place(x=30, y=100) 474 | 475 | tx = tk.Entry(windo, width=20, bg="yellow", fg="red", font=('times', 23, ' bold ')) 476 | tx.place(x=250, y=105) 477 | 478 | fill_a = tk.Button(windo, text="Fill Attendance", fg="white",command=Fillattendances, bg="deep pink", width=20, height=2, 479 | activebackground="Red", font=('times', 15, ' bold ')) 480 | fill_a.place(x=250, y=160) 481 | windo.mainloop() 482 | 483 | def admin_panel(): 484 | win = tk.Tk() 485 | win.iconbitmap('AMS.ico') 486 | win.title("LogIn") 487 | win.geometry('880x420') 488 | win.configure(background='snow') 489 | 490 | def log_in(): 491 | username = un_entr.get() 492 | password = pw_entr.get() 493 | 494 | if username == 'Ritu Kandari' : 495 | if password == 'igdtuw': 496 | win.destroy() 497 | import csv 498 | import tkinter 499 | root = tkinter.Tk() 500 | root.title("Student Details") 501 | root.configure(background='snow') 502 | 503 | cs = 'C:/Python36/Attendace_system_major_project/StudentDetails/StudentDetails.csv' 504 | with open(cs, newline="") as file: 505 | reader = csv.reader(file) 506 | r = 0 507 | 508 | for col in reader: 509 | c = 0 510 | for row in col: 511 | # i've added some styling 512 | label = tkinter.Label(root, width=8, height=1, fg="black", font=('times', 15, ' bold '), 513 | bg="lawn green", text=row, relief=tkinter.RIDGE) 514 | label.grid(row=r, column=c) 515 | c += 1 516 | r += 1 517 | root.mainloop() 518 | else: 519 | valid = 'Incorrect ID or Password' 520 | Nt.configure(text=valid, bg="red", fg="black", width=38, font=('times', 19, 'bold')) 521 | Nt.place(x=120, y=350) 522 | 523 | else: 524 | valid ='Incorrect ID or Password' 525 | Nt.configure(text=valid, bg="red", fg="black", width=38, font=('times', 19, 'bold')) 526 | Nt.place(x=120, y=350) 527 | 528 | 529 | Nt = tk.Label(win, text="Attendance filled Successfully", bg="Green", fg="white", width=40, 530 | height=2, font=('times', 19, 'bold')) 531 | # Nt.place(x=120, y=350) 532 | 533 | un = tk.Label(win, text="Enter username", width=15, height=2, fg="white", bg="blue2", 534 | font=('times', 15, ' bold ')) 535 | un.place(x=30, y=50) 536 | 537 | pw = tk.Label(win, text="Enter password", width=15, height=2, fg="white", bg="blue2", 538 | font=('times', 15, ' bold ')) 539 | pw.place(x=30, y=150) 540 | 541 | def c00(): 542 | un_entr.delete(first=0, last=22) 543 | 544 | un_entr = tk.Entry(win, width=20, bg="yellow", fg="red", font=('times', 23, ' bold ')) 545 | un_entr.place(x=290, y=55) 546 | 547 | def c11(): 548 | pw_entr.delete(first=0, last=22) 549 | 550 | pw_entr = tk.Entry(win, width=20,show="*", bg="yellow", fg="red", font=('times', 23, ' bold ')) 551 | pw_entr.place(x=290, y=155) 552 | 553 | c0 = tk.Button(win, text="Clear", command=c00, fg="black", bg="deep pink", width=10, height=1, 554 | activebackground="Red", font=('times', 15, ' bold ')) 555 | c0.place(x=690, y=55) 556 | 557 | c1 = tk.Button(win, text="Clear", command=c11, fg="black", bg="deep pink", width=10, height=1, 558 | activebackground="Red", font=('times', 15, ' bold ')) 559 | c1.place(x=690, y=155) 560 | 561 | Login = tk.Button(win, text="LogIn", fg="black", bg="lime green", width=20, 562 | height=2, 563 | activebackground="Red",command=log_in, font=('times', 15, ' bold ')) 564 | Login.place(x=290, y=250) 565 | win.mainloop() 566 | 567 | 568 | ###For train the model 569 | def trainimg(): 570 | recognizer = cv2.face.LBPHFaceRecognizer_create() 571 | global detector 572 | detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") 573 | try: 574 | global faces,Id 575 | faces, Id = getImagesAndLabels("TrainingImage") 576 | except Exception as e: 577 | l='please make "TrainingImage" folder & put Images' 578 | Notification.configure(text=l, bg="SpringGreen3", width=50, font=('times', 18, 'bold')) 579 | Notification.place(x=350, y=400) 580 | 581 | recognizer.train(faces, np.array(Id)) 582 | try: 583 | recognizer.save("TrainingImageLabel\Trainner.yml") 584 | except Exception as e: 585 | q='Please make "TrainingImageLabel" folder' 586 | Notification.configure(text=q, bg="SpringGreen3", width=50, font=('times', 18, 'bold')) 587 | Notification.place(x=350, y=400) 588 | 589 | res = "Model Trained" # +",".join(str(f) for f in Id) 590 | Notification.configure(text=res, bg="SpringGreen3", width=50, font=('times', 18, 'bold')) 591 | Notification.place(x=250, y=400) 592 | 593 | def getImagesAndLabels(path): 594 | imagePaths = [os.path.join(path, f) for f in os.listdir(path)] 595 | # create empth face list 596 | faceSamples = [] 597 | # create empty ID list 598 | Ids = [] 599 | # now looping through all the image paths and loading the Ids and the images 600 | for imagePath in imagePaths: 601 | # loading the image and converting it to gray scale 602 | pilImage = Image.open(imagePath).convert('L') 603 | # Now we are converting the PIL image into numpy array 604 | imageNp = np.array(pilImage, 'uint8') 605 | # getting the Id from the image 606 | 607 | Id = int(os.path.split(imagePath)[-1].split(".")[1]) 608 | # extract the face from the training image sample 609 | faces = detector.detectMultiScale(imageNp) 610 | # If a face is there then append that in the list as well as Id of it 611 | for (x, y, w, h) in faces: 612 | faceSamples.append(imageNp[y:y + h, x:x + w]) 613 | Ids.append(Id) 614 | return faceSamples, Ids 615 | 616 | window.grid_rowconfigure(0, weight=1) 617 | window.grid_columnconfigure(0, weight=1) 618 | window.iconbitmap('AMS.ico') 619 | 620 | def on_closing(): 621 | from tkinter import messagebox 622 | if messagebox.askokcancel("Quit", "Do you want to quit?"): 623 | window.destroy() 624 | window.protocol("WM_DELETE_WINDOW", on_closing) 625 | 626 | message = tk.Label(window, text="Face-Recognition-Based-Attendance-Management-System", bg="cyan", fg="black", width=50, 627 | height=3, font=('times', 30, 'italic bold ')) 628 | 629 | message.place(x=80, y=20) 630 | 631 | Notification = tk.Label(window, text="All things good", bg="Green", fg="white", width=15, 632 | height=3, font=('times', 17, 'bold')) 633 | 634 | lbl = tk.Label(window, text="Enter Enrollment", width=20, height=2, fg="black", bg="deep pink", font=('times', 15, ' bold ')) 635 | lbl.place(x=200, y=200) 636 | 637 | def testVal(inStr,acttyp): 638 | if acttyp == '1': #insert 639 | if not inStr.isdigit(): 640 | return False 641 | return True 642 | 643 | txt = tk.Entry(window, validate="key", width=20, bg="yellow", fg="red", font=('times', 25, ' bold ')) 644 | txt['validatecommand'] = (txt.register(testVal),'%P','%d') 645 | txt.place(x=550, y=210) 646 | 647 | lbl2 = tk.Label(window, text="Enter Name", width=20, fg="black", bg="deep pink", height=2, font=('times', 15, ' bold ')) 648 | lbl2.place(x=200, y=300) 649 | 650 | txt2 = tk.Entry(window, width=20, bg="yellow", fg="red", font=('times', 25, ' bold ')) 651 | txt2.place(x=550, y=310) 652 | 653 | clearButton = tk.Button(window, text="Clear",command=clear,fg="black" ,bg="deep pink" ,width=10 ,height=1 ,activebackground = "Red" ,font=('times', 15, ' bold ')) 654 | clearButton.place(x=950, y=210) 655 | 656 | clearButton1 = tk.Button(window, text="Clear",command=clear1,fg="black" ,bg="deep pink" ,width=10 ,height=1, activebackground = "Red" ,font=('times', 15, ' bold ')) 657 | clearButton1.place(x=950, y=310) 658 | 659 | AP = tk.Button(window, text="Check Register students",command=admin_panel,fg="black" ,bg="cyan" ,width=19 ,height=1, activebackground = "Red" ,font=('times', 15, ' bold ')) 660 | AP.place(x=990, y=410) 661 | 662 | takeImg = tk.Button(window, text="Take Images",command=take_img,fg="white" ,bg="blue2" ,width=20 ,height=3, activebackground = "Red" ,font=('times', 15, ' bold ')) 663 | takeImg.place(x=90, y=500) 664 | 665 | trainImg = tk.Button(window, text="Train Images",fg="black",command=trainimg ,bg="lawn green" ,width=20 ,height=3, activebackground = "Red" ,font=('times', 15, ' bold ')) 666 | trainImg.place(x=390, y=500) 667 | 668 | FA = tk.Button(window, text="Automatic Attendace",fg="white",command=subjectchoose ,bg="blue2" ,width=20 ,height=3, activebackground = "Red" ,font=('times', 15, ' bold ')) 669 | FA.place(x=690, y=500) 670 | 671 | quitWindow = tk.Button(window, text="Manually Fill Attendance", command=manually_fill ,fg="black" ,bg="lawn green" ,width=20 ,height=3, activebackground = "Red" ,font=('times', 15, ' bold ')) 672 | quitWindow.place(x=990, y=500) 673 | 674 | window.mainloop() 675 | --------------------------------------------------------------------------------