-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstudent.py
583 lines (485 loc) · 28.5 KB
/
student.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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
from tkinter import*
from tkinter import ttk
from PIL import Image,ImageTk
from tkinter import messagebox
import mysql.connector
import cv2
import numpy as np
# Testing Connection
"""
conn = mysql.connector.connect(user='root', password='2912002',host='localhost',database='face_recognition',port=3306)
cursor = conn.cursor()
cursor.execute("show databases")
data = cursor.fetchall()
print(data)
conn.close()
"""
class Student:
def __init__(self,root):
self.root=root
self.root.state('zoomed')
self.root.title("Hệ thống quản lý điểm danh sử dụng nhận dạng khuôn mặt")
#-----------Variables-------------------
self.var_dep=StringVar()
self.var_course=StringVar()
self.var_year=StringVar()
self.var_semester=StringVar()
self.var_std_id=StringVar()
self.var_std_name=StringVar()
self.var_div=StringVar()
self.var_roll=StringVar()
self.var_gender=StringVar()
self.var_dob=StringVar()
self.var_email=StringVar()
self.var_mob=StringVar()
self.var_address=StringVar()
self.var_teacher=StringVar()
# This part is image labels setting start
# first header image
img=Image.open(r"D:\VKU\DoAnCoSo4\Attendance_Management_System_Using_Face_Recognition\Images_GUI\banner2.png")
img=img.resize((1280,130),Image.ANTIALIAS)
self.photoimg=ImageTk.PhotoImage(img)
# set image as lable
f_lb1 = Label(self.root,image=self.photoimg)
f_lb1.place(x=0,y=0,width=1280,height=130)
# backgorund image
bg1=Image.open(r"D:\VKU\DoAnCoSo4\Attendance_Management_System_Using_Face_Recognition\Images_GUI\bg4.jpg")
bg1=bg1.resize((1280,500),Image.ANTIALIAS)
self.photobg1=ImageTk.PhotoImage(bg1)
# set image as lable
bg_img = Label(self.root,image=self.photobg1)
bg_img.place(x=0,y=145,width=1280,height=500)
#title section
title_lb1 = Label(bg_img,text="VKU - Quản lí thông tin sinh viên",font=("verdana",20,"bold"),bg="navyblue",fg="white")
title_lb1.place(x=0,y=0,width=1280,height=40)
# Creating Frame
main_frame = Frame(bg_img,bd=2,bg="white") #bd mean border
main_frame.place(x=0,y=40,width=1280,height=500)
# Left Label Frame
left_frame = LabelFrame(main_frame,bd=2,bg="white",relief=RIDGE,text="Thông tin sinh viên",font=("verdana",10,"bold"),fg="navyblue")
left_frame.place(x=7,y=7,width=590,height=450)
# Current Course
current_course_frame = LabelFrame(left_frame,bd=2,bg="white",relief=RIDGE,text="Thông tin khóa học",font=("verdana",10,"bold"),fg="navyblue")
current_course_frame.place(x=10,y=5,width=560,height=120)
#label Department
dep_label=Label(current_course_frame,text="Chuyên ngành",font=("verdana",10,"bold"),bg="white",fg="navyblue")
dep_label.grid(row=0,column=0,padx=5,pady=12)
#combo box
dep_combo=ttk.Combobox(current_course_frame,textvariable=self.var_dep,width=15,font=("verdana",10,"bold"),state="readonly")
dep_combo["values"]=("Công nghệ kỹ thuật máy tính","Công nghệ thông tin","Khoa học dữ liệu và AI","Thiết kế mĩ thuật số","Quản trị kinh doanh","Logistics và chuỗi cung ứng")
dep_combo.current(0)
dep_combo.grid(row=0,column=1,padx=5,pady=12,sticky=W)
# -----------------------------------------------------
#label Course
cou_label=Label(current_course_frame,text="Hệ đào tạo",font=("verdana",10,"bold"),bg="white",fg="navyblue")
cou_label.grid(row=0,column=2,padx=5,pady=12)
#combo box
cou_combo=ttk.Combobox(current_course_frame,textvariable=self.var_course,width=15,font=("verdana",10,"bold"),state="readonly")
cou_combo["values"]=("Chính quy","Liên Thông")
cou_combo.current(0)
cou_combo.grid(row=0,column=3,padx=5,pady=12,sticky=W)
#-------------------------------------------------------------
#label Year
year_label=Label(current_course_frame,text="Năm học",font=("verdana",10,"bold"),bg="white",fg="navyblue")
year_label.grid(row=1,column=0,padx=5,sticky=W)
#combo box
year_combo=ttk.Combobox(current_course_frame,textvariable=self.var_year,width=15,font=("verdana",10,"bold"),state="readonly")
year_combo["values"]=("2020","2021","2022","2023","2024")
year_combo.current(0)
year_combo.grid(row=1,column=1,padx=5,pady=12,sticky=W)
#-----------------------------------------------------------------
#label Semester
year_label=Label(current_course_frame,text="Học kì",font=("verdana",10,"bold"),bg="white",fg="navyblue")
year_label.grid(row=1,column=2,padx=5,sticky=W)
#combo box
year_combo=ttk.Combobox(current_course_frame,textvariable=self.var_semester,width=15,font=("verdana",10,"bold"),state="readonly")
year_combo["values"]=("Học kì-1","Học kì-2")
year_combo.current(0)
year_combo.grid(row=1,column=3,padx=5,pady=15,sticky=W)
#Class Student Information
class_Student_frame = LabelFrame(left_frame,bd=2,bg="white",relief=RIDGE,text="Thông tin lớp học",font=("verdana",10,"bold"),fg="navyblue")
class_Student_frame.place(x=10,y=130,width=560,height=230)
#Student id
studentId_label = Label(class_Student_frame,text="ID Sinh Viên:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
studentId_label.grid(row=0,column=0,padx=5,pady=5,sticky=W)
studentId_entry = ttk.Entry(class_Student_frame,textvariable=self.var_std_id,width=15,font=("verdana",10,"bold"))
studentId_entry.grid(row=0,column=1,padx=5,pady=5,sticky=W)
#Student name
student_name_label = Label(class_Student_frame,text="Tên Sinh Viên:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
student_name_label.grid(row=0,column=2,padx=5,pady=5,sticky=W)
student_name_entry = ttk.Entry(class_Student_frame,textvariable=self.var_std_name,width=15,font=("verdana",10,"bold"))
student_name_entry.grid(row=0,column=3,padx=5,pady=5,sticky=W)
#Class Didvision
student_div_label = Label(class_Student_frame,text="Buổi học:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
student_div_label.grid(row=1,column=0,padx=5,pady=5,sticky=W)
div_combo=ttk.Combobox(class_Student_frame,textvariable=self.var_div,width=13,font=("verdana",10,"bold"),state="readonly")
div_combo["values"]=("Sáng","Chiều")
div_combo.current(0)
div_combo.grid(row=1,column=1,padx=5,pady=5,sticky=W)
#Roll No
student_roll_label = Label(class_Student_frame,text="Mã Sinh Viên:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
student_roll_label.grid(row=1,column=2,padx=5,pady=5,sticky=W)
student_roll_entry = ttk.Entry(class_Student_frame,textvariable=self.var_roll,width=15,font=("verdana",10,"bold"))
student_roll_entry.grid(row=1,column=3,padx=5,pady=5,sticky=W)
#Gender
student_gender_label = Label(class_Student_frame,text="Giới tính:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
student_gender_label.grid(row=2,column=0,padx=5,pady=5,sticky=W)
#combo box
gender_combo=ttk.Combobox(class_Student_frame,textvariable=self.var_gender,width=13,font=("verdana",10,"bold"),state="readonly")
gender_combo["values"]=("Nam","Nữ","Khác")
gender_combo.current(0)
gender_combo.grid(row=2,column=1,padx=5,pady=5,sticky=W)
#Date of Birth
student_dob_label = Label(class_Student_frame,text="Ngày Sinh:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
student_dob_label.grid(row=2,column=2,padx=5,pady=5,sticky=W)
student_dob_entry = ttk.Entry(class_Student_frame,textvariable=self.var_dob,width=15,font=("verdana",10,"bold"))
student_dob_entry.grid(row=2,column=3,padx=5,pady=5,sticky=W)
#Email
student_email_label = Label(class_Student_frame,text="Email:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
student_email_label.grid(row=3,column=0,padx=5,pady=5,sticky=W)
student_email_entry = ttk.Entry(class_Student_frame,textvariable=self.var_email,width=15,font=("verdana",10,"bold"))
student_email_entry.grid(row=3,column=1,padx=5,pady=5,sticky=W)
#Phone Number
student_mob_label = Label(class_Student_frame,text="Di động:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
student_mob_label.grid(row=3,column=2,padx=5,pady=5,sticky=W)
student_mob_entry = ttk.Entry(class_Student_frame,textvariable=self.var_mob,width=15,font=("verdana",10,"bold"))
student_mob_entry.grid(row=3,column=3,padx=5,pady=5,sticky=W)
#Address
student_address_label = Label(class_Student_frame,text="Địa chỉ:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
student_address_label.grid(row=4,column=0,padx=5,pady=5,sticky=W)
student_address_entry = ttk.Entry(class_Student_frame,textvariable=self.var_address,width=15,font=("verdana",10,"bold"))
student_address_entry.grid(row=4,column=1,padx=5,pady=5,sticky=W)
#Teacher Name
student_tutor_label = Label(class_Student_frame,text="Giảng viên:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
student_tutor_label.grid(row=4,column=2,padx=5,pady=5,sticky=W)
student_tutor_entry = ttk.Entry(class_Student_frame,textvariable=self.var_teacher,width=15,font=("verdana",10,"bold"))
student_tutor_entry.grid(row=4,column=3,padx=5,pady=5,sticky=W)
#Radio Buttons
self.var_radio1=StringVar()
radiobtn1=ttk.Radiobutton(class_Student_frame,text="Có ảnh",variable=self.var_radio1,value="Có Ảnh")
radiobtn1.grid(row=5,column=0,padx=5,pady=5,sticky=W)
radiobtn1=ttk.Radiobutton(class_Student_frame,text="Không ảnh",variable=self.var_radio1,value="Không Ảnh")
radiobtn1.grid(row=5,column=1,padx=5,pady=5,sticky=W)
#Button Frame
btn_frame = Frame(left_frame,bg="white",relief=RIDGE)
btn_frame.place(x=10,y=370,width=570,height=45)
#save button
save_btn=Button(btn_frame,command=self.add_data,text="Lưu",width=7,font=("verdana",10,"bold"),fg="white",bg="navyblue")
save_btn.grid(row=0,column=0,padx=5,pady=10,sticky=W)
#update button
update_btn=Button(btn_frame,command=self.update_data,text="Sửa",width=7,font=("verdana",10,"bold"),fg="white",bg="navyblue")
update_btn.grid(row=0,column=1,padx=5,pady=8,sticky=W)
#delete button
del_btn=Button(btn_frame,command=self.delete_data,text="Xóa",width=7,font=("verdana",10,"bold"),fg="white",bg="navyblue")
del_btn.grid(row=0,column=2,padx=5,pady=10,sticky=W)
#reset button
reset_btn=Button(btn_frame,command=self.reset_data,text="Reset",width=7,font=("verdana",10,"bold"),fg="white",bg="navyblue")
reset_btn.grid(row=0,column=3,padx=5,pady=10,sticky=W)
#take photo button
take_photo_btn=Button(btn_frame,command=self.generate_dataset,text="Lấy Ảnh",width=9,font=("verdana",10,"bold"),fg="white",bg="navyblue")
take_photo_btn.grid(row=0,column=4,padx=5,pady=10,sticky=W)
#update photo button
update_photo_btn=Button(btn_frame,text="Sửa Ảnh",width=9,font=("verdana",10,"bold"),fg="white",bg="navyblue")
update_photo_btn.grid(row=0,column=5,padx=5,pady=10,sticky=W)
#----------------------------------------------------------------------
# Right Label Frame
right_frame = LabelFrame(main_frame,bd=2,bg="white",relief=RIDGE,text="Danh sách",font=("verdana",10,"bold"),fg="navyblue")
right_frame.place(x=620,y=8,width=660,height=450)
#Searching System in Right Label Frame
search_frame = LabelFrame(right_frame,bd=2,bg="white",relief=RIDGE,text="Hệ thống tìm kiếm",font=("verdana",10,"bold"),fg="navyblue")
search_frame.place(x=10,y=5,width=635,height=80)
#Phone Number
search_label = Label(search_frame,text="Tìm kiếm theo:",font=("verdana",10,"bold"),fg="navyblue",bg="white")
search_label.grid(row=0,column=0,padx=5,pady=5,sticky=W)
self.var_searchTX=StringVar()
#combo box
search_combo=ttk.Combobox(search_frame,textvariable=self.var_searchTX,width=12,font=("verdana",10,"bold"),state="readonly")
search_combo["values"]=("Mã-Sinh-Viên","Email")
search_combo.current(0)
search_combo.grid(row=0,column=1,padx=5,pady=15,sticky=W)
self.var_search=StringVar()
search_entry = ttk.Entry(search_frame,textvariable=self.var_search,width=12,font=("verdana",10,"bold"))
search_entry.grid(row=0,column=2,padx=5,pady=5,sticky=W)
search_btn=Button(search_frame,command=self.search_data,text="Tìm kiếm",width=10,font=("verdana",10,"bold"),fg="white",bg="navyblue")
search_btn.grid(row=0,column=3,padx=5,pady=10,sticky=W)
showAll_btn=Button(search_frame,command=self.fetch_data,text="Xem tất cả",width=10,font=("verdana",10,"bold"),fg="white",bg="navyblue")
showAll_btn.grid(row=0,column=4,padx=5,pady=10,sticky=W)
# -----------------------------Table Frame-------------------------------------------------
#Table Frame
#Searching System in Right Label Frame
table_frame = Frame(right_frame,bd=2,bg="white",relief=RIDGE)
table_frame.place(x=10,y=90,width=630,height=330)
#scroll bar
scroll_x = ttk.Scrollbar(table_frame,orient=HORIZONTAL)
scroll_y = ttk.Scrollbar(table_frame,orient=VERTICAL)
#create table
self.student_table = ttk.Treeview(table_frame,column=("ID","Name","Dep","Course","Year","Sem","Div","Gender","DOB","Mob-No","Address","Roll-No","Email","Teacher","Photo"),xscrollcommand=scroll_x.set,yscrollcommand=scroll_y.set)
scroll_x.pack(side=BOTTOM,fill=X)
scroll_y.pack(side=RIGHT,fill=Y)
scroll_x.config(command=self.student_table.xview)
scroll_y.config(command=self.student_table.yview)
self.student_table.heading("ID",text="ID Sinh viên")
self.student_table.heading("Name",text="Tên sinh viên")
self.student_table.heading("Dep",text="Chuyên ngành")
self.student_table.heading("Course",text="Hệ đào tạo")
self.student_table.heading("Year",text="Năm học")
self.student_table.heading("Sem",text="Học kì")
self.student_table.heading("Div",text="Buổi học")
self.student_table.heading("Gender",text="Giới tính")
self.student_table.heading("DOB",text="Ngày sinh")
self.student_table.heading("Mob-No",text="Di động")
self.student_table.heading("Address",text="Địa chỉ")
self.student_table.heading("Roll-No",text="Mã Sinh viên")
self.student_table.heading("Email",text="Email")
self.student_table.heading("Teacher",text="Giảng viên")
self.student_table.heading("Photo",text="Ảnh")
self.student_table["show"]="headings"
# Set Width of Colums
self.student_table.column("ID",width=20)
self.student_table.column("Name",width=120)
self.student_table.column("Dep",width=120)
self.student_table.column("Course",width=120)
self.student_table.column("Year",width=120)
self.student_table.column("Sem",width=120)
self.student_table.column("Div",width=120)
self.student_table.column("Gender",width=120)
self.student_table.column("DOB",width=120)
self.student_table.column("Mob-No",width=120)
self.student_table.column("Address",width=120)
self.student_table.column("Roll-No",width=120)
self.student_table.column("Email",width=120)
self.student_table.column("Teacher",width=120)
self.student_table.column("Photo",width=120)
self.student_table.pack(fill=BOTH,expand=1)
self.student_table.bind("<ButtonRelease>",self.get_cursor)
self.fetch_data()
# ==================Function Decleration==============================
def add_data(self):
if self.var_dep.get()=="Select Department" or self.var_course.get=="Select Course" or self.var_year.get()=="Select Year" or self.var_semester.get()=="Select Semester" or self.var_std_id.get()=="" or self.var_std_name.get()=="" or self.var_div.get()=="" or self.var_roll.get()=="" or self.var_gender.get()=="" or self.var_dob.get()=="" or self.var_email.get()=="" or self.var_mob.get()=="" or self.var_address.get()=="" or self.var_teacher.get()=="":
messagebox.showerror("Error","Vui lòng điền vào tất cả các trường là bắt buộc!",parent=self.root)
else:
try:
conn = mysql.connector.connect(user='root', password='2912002',host='localhost',database='face_recognition',port=3306)
mycursor = conn.cursor()
mycursor.execute("insert into student values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",(
self.var_std_id.get(),
self.var_std_name.get(),
self.var_dep.get(),
self.var_course.get(),
self.var_year.get(),
self.var_semester.get(),
self.var_div.get(),
self.var_gender.get(),
self.var_dob.get(),
self.var_mob.get(),
self.var_address.get(),
self.var_roll.get(),
self.var_email.get(),
self.var_teacher.get(),
self.var_radio1.get()
))
conn.commit()
self.fetch_data()
conn.close()
messagebox.showinfo("Success","Tất cả các bản ghi đã được lưu!",parent=self.root)
except Exception as es:
messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root)
# ===========================Fetch data form database to table ================================
def fetch_data(self):
conn = mysql.connector.connect(user='root', password='2912002',host='localhost',database='face_recognition',port=3306)
mycursor = conn.cursor()
mycursor.execute("select * from student")
data=mycursor.fetchall()
if len(data)!= 0:
self.student_table.delete(*self.student_table.get_children())
for i in data:
self.student_table.insert("",END,values=i)
conn.commit()
conn.close()
#================================get cursor function=======================
def get_cursor(self,event=""):
cursor_focus = self.student_table.focus()
content = self.student_table.item(cursor_focus)
data = content["values"]
self.var_std_id.set(data[0]),
self.var_std_name.set(data[1]),
self.var_dep.set(data[2]),
self.var_course.set(data[3]),
self.var_year.set(data[4]),
self.var_semester.set(data[5]),
self.var_div.set(data[6]),
self.var_gender.set(data[7]),
self.var_dob.set(data[8]),
self.var_mob.set(data[9]),
self.var_address.set(data[10]),
self.var_roll.set(data[11]),
self.var_email.set(data[12]),
self.var_teacher.set(data[13]),
self.var_radio1.set(data[14])
# ========================================Update Function==========================
def update_data(self):
if self.var_dep.get()=="Select Department" or self.var_course.get=="Select Course" or self.var_year.get()=="Select Year" or self.var_semester.get()=="Select Semester" or self.var_std_id.get()=="" or self.var_std_name.get()=="" or self.var_div.get()=="" or self.var_roll.get()=="" or self.var_gender.get()=="" or self.var_dob.get()=="" or self.var_email.get()=="" or self.var_mob.get()=="" or self.var_address.get()=="" or self.var_teacher.get()=="":
messagebox.showerror("Error","Vui lòng điền vào tất cả các trường là bắt buộc!",parent=self.root)
else:
try:
Update=messagebox.askyesno("Update","Bạn có muốn sửa lại không!",parent=self.root)
if Update > 0:
conn = mysql.connector.connect(user='root', password='2912002',host='localhost',database='face_recognition',port=3306)
mycursor = conn.cursor()
mycursor.execute("update student set Name=%s,Department=%s,Course=%s,Year=%s,Semester=%s,Division=%s,Gender=%s,DOB=%s,Mobile_No=%s,Address=%s,Roll_No=%s,Email=%s,Teacher_Name=%s,PhotoSample=%s where Student_ID=%s",(
self.var_std_name.get(),
self.var_dep.get(),
self.var_course.get(),
self.var_year.get(),
self.var_semester.get(),
self.var_div.get(),
self.var_gender.get(),
self.var_dob.get(),
self.var_mob.get(),
self.var_address.get(),
self.var_roll.get(),
self.var_email.get(),
self.var_teacher.get(),
self.var_radio1.get(),
self.var_std_id.get()
))
else:
if not Update:
return
messagebox.showinfo("Success","Cập nhật thành công!",parent=self.root)
conn.commit()
self.fetch_data()
conn.close()
except Exception as es:
messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root)
#==============================Delete Function=========================================
def delete_data(self):
if self.var_std_id.get()=="":
messagebox.showerror("Error","Student Id phải bắt buộc!",parent=self.root)
else:
try:
delete=messagebox.askyesno("Delete","Bạn có muốn xóa không?",parent=self.root)
if delete>0:
conn = mysql.connector.connect(user='root', password='2912002',host='localhost',database='face_recognition',port=3306)
mycursor = conn.cursor()
sql="delete from student where Student_ID=%s"
val=(self.var_std_id.get(),)
mycursor.execute(sql,val)
else:
if not delete:
return
conn.commit()
self.fetch_data()
conn.close()
messagebox.showinfo("Delete","Xóa Thành Công!",parent=self.root)
except Exception as es:
messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root)
# Reset Function
def reset_data(self):
self.var_std_id.set(""),
self.var_std_name.set(""),
self.var_dep.set(""),
self.var_course.set(""),
self.var_year.set(""),
self.var_semester.set(""),
self.var_div.set(""),
self.var_gender.set(""),
self.var_dob.set(""),
self.var_mob.set(""),
self.var_address.set(""),
self.var_roll.set(""),
self.var_email.set(""),
self.var_teacher.set(""),
self.var_radio1.set("")
# ===========================Search Data===================
def search_data(self):
if self.var_search.get()=="" or self.var_searchTX.get()=="Select":
messagebox.showerror("Error","Select Combo option and enter entry box",parent=self.root)
else:
try:
conn = mysql.connector.connect(user='root', password='2912002',host='localhost',database='face_recognition',port=3306)
my_cursor = conn.cursor()
sql = "SELECT Student_ID,Name,Department,Course,Year,Semester,Division,Gender,DOB,Mobile_No,Address,Roll_No,Email,Teacher_Name,PhotoSample FROM student where Roll_No='" +str(self.var_search.get()) + "'"
my_cursor.execute(sql)
# my_cursor.execute("select * from student where Roll_No= " +str(self.var_search.get())+" "+str(self.var_searchTX.get())+"")
rows=my_cursor.fetchall()
if len(rows)!=0:
self.student_table.delete(*self.student_table.get_children())
for i in rows:
self.student_table.insert("",END,values=i)
if rows==None:
messagebox.showerror("Error","Data Not Found",parent=self.root)
conn.commit()
conn.close()
except Exception as es:
messagebox.showerror("Error",f"Due To :{str(es)}",parent=self.root)
#=====================This part is related to Opencv Camera part=======================
# ==================================Generate Data set take image=========================
def generate_dataset(self):
if self.var_dep.get()=="Select Department" or self.var_course.get=="Select Course" or self.var_year.get()=="Select Year" or self.var_semester.get()=="Select Semester" or self.var_std_id.get()=="" or self.var_std_name.get()=="" or self.var_div.get()=="" or self.var_roll.get()=="" or self.var_gender.get()=="" or self.var_dob.get()=="" or self.var_email.get()=="" or self.var_mob.get()=="" or self.var_address.get()=="" or self.var_teacher.get()=="":
messagebox.showerror("Error","Vui lòng điền vào tất cả các trường là bắt buộc!",parent=self.root)
else:
try:
conn = mysql.connector.connect(user='root', password='2912002',host='localhost',database='face_recognition',port=3306)
mycursor = conn.cursor()
mycursor.execute("select * from student")
myreslut = mycursor.fetchall()
id=0
for x in myreslut:
id+=1
mycursor.execute("update student set Name=%s,Department=%s,Course=%s,Year=%s,Semester=%s,Division=%s,Gender=%s,DOB=%s,Mobile_No=%s,Address=%s,Roll_No=%s,Email=%s,Teacher_Name=%s,PhotoSample=%s where Student_ID=%s",(
self.var_std_name.get(),
self.var_dep.get(),
self.var_course.get(),
self.var_year.get(),
self.var_semester.get(),
self.var_div.get(),
self.var_gender.get(),
self.var_dob.get(),
self.var_mob.get(),
self.var_address.get(),
self.var_roll.get(),
self.var_email.get(),
self.var_teacher.get(),
self.var_radio1.get(),
self.var_std_id.get()==id+1
))
conn.commit()
self.fetch_data()
self.reset_data()
conn.close()
# ====================part of opencv=======================
face_classifier = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
def face_croped(img):
# conver gary sacle
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
faces = face_classifier.detectMultiScale(gray,1.3,5)
#Scaling factor 1.3
# Minimum naber 5
for (x,y,w,h) in faces:
face_croped=img[y:y+h,x:x+w]
return face_croped
cap=cv2.VideoCapture(0)
img_id=0
while True:
ret,my_frame=cap.read()
if face_croped(my_frame) is not None:
img_id+=1
face=cv2.resize(face_croped(my_frame),(200,200))
face=cv2.cvtColor(face,cv2.COLOR_BGR2GRAY)
file_path="data_img/stdudent."+str(id)+"."+str(img_id)+".jpg"
cv2.imwrite(file_path,face)
cv2.putText(face,str(img_id),(50,50),cv2.FONT_HERSHEY_COMPLEX,2,(0,255,0),2)
cv2.imshow("Capture Images",face)
if cv2.waitKey(1)==13 or int(img_id)==100:
break
cap.release()
cv2.destroyAllWindows()
messagebox.showinfo("Result","Đã hoàn tất tạo tập dữ liệu!",parent=self.root)
except Exception as es:
messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root)
# main class object
if __name__ == "__main__":
root=Tk()
obj=Student(root)
root.mainloop()