├── attendance.csv ├── Database.sql ├── train.py ├── README.md ├── developer.py ├── face_recognizer.py ├── support.py ├── Registers.py ├── main.py ├── login.py ├── attendence.py └── student.py /attendance.csv: -------------------------------------------------------------------------------- 1 | 1, 20scse1010767, Nadeem Sarwar, 18:41:49, 08/02/2024, Present -------------------------------------------------------------------------------- /Database.sql: -------------------------------------------------------------------------------- 1 | ---------Create Database------ 2 | 3 | CREATE DATABASE face_recognizer; 4 | 5 | --- using This Databse---- 6 | 7 | SELECT * FROM face_recognizer.student; 8 | 9 | -----------------For using student data--------- 10 | ----------- creating a table , table name student 11 | CREATE TABLE face_recognizer.student ( 12 | Dep VARCHAR(45) NULL, 13 | course VARCHAR(45) NULL, 14 | Year VARCHAR(45) NULL, 15 | semester VARCHAR(45) NULL, 16 | Student_id VARCHAR(45) NOT NULL, 17 | Name VARCHAR(45) NULL, 18 | Division VARCHAR(45) NULL, 19 | Roll VARCHAR(45) NULL, 20 | Gender VARCHAR(45) NULL, 21 | Dob VARCHAR(45) NULL, 22 | Email VARCHAR(45) NULL, 23 | Phone VARCHAR(45) NULL, 24 | Address VARCHAR(45) NULL, 25 | Teacher VARCHAR(45) NULL, 26 | PhotoSample VARCHAR(45) NULL, 27 | PRIMARY KEY (Student_id)); 28 | 29 | ---------------- For Manage Attendence----------- 30 | 31 | CREATE TABLE `stdattendance` ( 32 | `std_id` int NOT NULL, 33 | `std_roll_no` varchar(45) DEFAULT NULL, 34 | `std_name` varchar(45) DEFAULT NULL, 35 | `std_time` varchar(45) DEFAULT NULL, 36 | `std_date` varchar(45) DEFAULT NULL, 37 | `std_attendance` varchar(45) DEFAULT NULL, 38 | PRIMARY KEY (`std_id`) 39 | ) 40 | 41 | ------------ For User Loogin --------- 42 | 43 | CREATE TABLE `regteach` ( 44 | `fname` varchar(150) DEFAULT NULL, 45 | `lname` varchar(150) DEFAULT NULL, 46 | `phone` varchar(45) DEFAULT NULL, 47 | `email` varchar(150) DEFAULT NULL, 48 | `ssq` varchar(150) DEFAULT NULL, 49 | `sa` varchar(150) DEFAULT NULL, 50 | `pwd` varchar(150) DEFAULT NULL 51 | ); 52 | -------------------------------------------------------------------------------- /train.py: -------------------------------------------------------------------------------- 1 | from tkinter import* 2 | from tkinter import ttk 3 | from PIL import Image, ImageTk 4 | from tkinter import messagebox 5 | import cv2 6 | import mysql.connector 7 | import os 8 | import numpy as np 9 | 10 | try: 11 | # Establish connection to MySQL database 12 | conn = mysql.connector.connect( 13 | host="localhost", 14 | user="root", 15 | password="Nadeem@786", 16 | database="face_recognizer" 17 | ) 18 | # If the connection is successful, print a success message 19 | print("Connected to MySQL database!") 20 | # Don't forget to close the connection when done 21 | conn.close() 22 | except Exception as e: 23 | # If there's an error, print the error message 24 | print("Error:", e) 25 | 26 | 27 | class Train: 28 | 29 | def __init__(self, root): 30 | self.root=root 31 | self.root.geometry("1530x790+0+0") 32 | self.root.title("face Recognition System") 33 | 34 | title_lbl=Label(self.root,text="TRAIN DATA SET",font=("times new roman",35,"bold"),bg="white", fg="red") 35 | title_lbl.place(x=0,y=0,width=1530, height=45) 36 | 37 | img_top=Image.open(r"image\facial_recognition_action.jpg") 38 | img_top=img_top.resize((1530,325),Image.ADAPTIVE) 39 | self.photoimg_top=ImageTk.PhotoImage(img_top) 40 | 41 | f_lbl =Label(self.root,image=self.photoimg_top) 42 | f_lbl.place(x=0,y=55, width=1530, height=325) 43 | 44 | b1_1=Button(self.root, text="TRAIN DATA",command=self.train_classifier ,cursor="hand2",font=("times new roman",30,"bold"),bg="red", fg="white") 45 | b1_1.place(x=0, y=380, width=1530, height=60) 46 | 47 | img_bottom=Image.open(r"image\facialrecognition.png") 48 | img_bottom=img_bottom.resize((1530,325),Image.ADAPTIVE) 49 | self.photoimg_bottom=ImageTk.PhotoImage(img_bottom) 50 | 51 | f_lbl =Label(self.root,image=self.photoimg_bottom) 52 | f_lbl.place(x=0,y=440, width=1530, height=325) 53 | 54 | ############ maain program ############## 55 | 56 | def train_classifier(self): 57 | data_dir = "data" 58 | path = [os.path.join(data_dir, file) for file in os.listdir(data_dir)] 59 | 60 | faces = [] 61 | ids = [] 62 | 63 | for image in path: 64 | img = cv2.imread(image, cv2.IMREAD_GRAYSCALE) 65 | imageNp = np.array(img, 'uint8') 66 | id = int(os.path.split(image)[1].split('.')[1]) 67 | 68 | faces.append(imageNp) 69 | ids.append(id) 70 | 71 | ids = np.array(ids) 72 | 73 | # Train Classifier 74 | clf = cv2.face.LBPHFaceRecognizer_create() 75 | clf.train(faces,ids) 76 | clf.save("classifier.xml") 77 | 78 | messagebox.showinfo("Result", "Training dataset completed!!", parent=self.root) 79 | 80 | 81 | 82 | if __name__ == "__main__": 83 | root=Tk() 84 | obj = Train(root) 85 | root.mainloop() -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ****Face Recognition Attendance System**** 2 | 3 | https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/f60d67a4-9a12-42c6-9166-3e456cccc982 4 | 5 | **Overview** 6 | The Face Recognition Attendance System is a software application designed to automate the attendance tracking process using facial recognition technology. 7 | This system allows users to easily record attendance by capturing and analyzing facial features, eliminating the need for manual attendance tracking methods. 8 | 9 | **Main Dashboard** 10 | The Main Dashboard serves as the central hub of the system, providing access to various functionalities and sections through intuitive buttons: 11 | ![Main Page](https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/19a7776c-c1a6-4934-a7ae-cc9d8a3316c2) 12 | 13 | **Student Management System** 14 | The Student Management System component facilitates the management of student records, including personal information, enrollment details, and course registrations. It provides functionalities such as adding new students, updating existing records, and generating student ID cards. 15 | **![Student Management System Page](https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/e1d70856-9fee-4d0d-9750-98c184642056) 16 | 17 | **Training Image Dataset** 18 | To train the facial recognition model, we utilize a carefully curated dataset of facial images. Each image in the dataset undergoes preprocessing, including conversion into threshold values, to enhance the accuracy of facial recognition algorithms. 19 | ![Train Data Set](https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/245e7e14-b73b-4fa7-832a-3be3fe13bf36) 20 | 21 | **Face Detection Component** 22 | The Face Detection Component utilizes advanced computer vision algorithms to detect and recognize human faces from images or video streams. It integrates with the facial recognition module to accurately identify individuals based on their facial features. 23 | ![Face scanning ](https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/90360a0e-94fa-4d51-b18b-9ff9c734788f) 24 | 25 | **Help & Support** 26 | For assistance or inquiries regarding the Face Recognition Attendance System, please refer to the following resources: 27 | ![Help Support Page](https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/4173324a-e7b1-4c51-9137-8ea12cce5215) 28 | 29 | **Developer Resources!** 30 | If you're interested in contributing to the Face Recognition Attendance System or exploring its underlying codebase, the following resources are available: 31 | ![Developer Page](https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/2147bd4a-28ef-4f3d-a93d-8b70ef568a5c) 32 | 33 | **Database Updation** 34 | The Database Updation module ensures seamless synchronization between the application's database and the latest attendance records. It handles data insertion, retrieval, and modification operations, ensuring data integrity and consistency. 35 | ![Sql Database](https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/8dc18813-61ed-4502-a13d-35022947e35a) 36 | 37 | **Admin Login** 38 | The Admin Login feature provides secure access to administrative functionalities, allowing authorized users to configure system settings, manage user accounts, and view attendance reports. It employs robust authentication mechanisms to prevent unauthorized access. 39 | ![Login Page](https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/6af0ceab-8a9f-4865-8049-e6b72e895568) 40 | 41 | **Registration Page** 42 | The Registration Page allows new users to register their profiles within the system. It collects relevant information, such as name, contact details, and facial images, to create unique user accounts. The registration process is streamlined and user-friendly. 43 | ![Register Page](https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/2a1ef585-65a0-4856-b649-298754f37eae) 44 | 45 | **User Authentication** 46 | User Authentication mechanisms verify the identity of users accessing the system, ensuring that only authorized individuals can perform specific actions. It employs techniques such as username-password authentication and two-factor authentication to enhance security. 47 | 48 | **Attendance Tracking** 49 | The Attendance Tracking module captures attendance data in real-time using facial recognition technology. It marks attendance for registered students based on their presence during scheduled sessions, eliminating the need for manual attendance recording. 50 | ![Attendance Details Page](https://github.com/MdNadeemSarwar/Face-Recognition-Attendance-System/assets/107212111/c9b336e3-458c-45f2-b394-f1a7a523ebad) 51 | -------------------------------------------------------------------------------- /developer.py: -------------------------------------------------------------------------------- 1 | from tkinter import* 2 | from tkinter import ttk 3 | from train import Train 4 | from PIL import Image,ImageTk 5 | from student import Student 6 | from train import Train 7 | import os 8 | import webbrowser 9 | 10 | class Developer: 11 | 12 | def __init__(self,root): 13 | self.root=root 14 | self.root.geometry("1530x790+0+0") 15 | self.root.title("face Recognition") 16 | 17 | # This part is image labels setting start 18 | # first header image 19 | img=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\coding.jpg") 20 | img=img.resize((1530,230),Image.ADAPTIVE) 21 | self.photoimg=ImageTk.PhotoImage(img) 22 | 23 | # set image as lable 24 | f_lb1 = Label(self.root,image=self.photoimg) 25 | f_lb1.place(x=0,y=0,width=1530,height=230) 26 | 27 | # backgorund image 28 | bg1=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\developer.jpg") 29 | bg1=bg1.resize((1530,710),Image.ADAPTIVE) 30 | self.photobg1=ImageTk.PhotoImage(bg1) 31 | 32 | # set image as lable 33 | bg_img = Label(self.root,image=self.photobg1) 34 | bg_img.place(x=0,y=145,width=1530,height=710) 35 | 36 | 37 | #title section 38 | title_lb1 = Label(bg_img,text="Developer",font=("verdana",20,"bold"),bg="navyblue",fg="white") 39 | title_lb1.place(x=0,y=0,width=1530,height=50) 40 | 41 | 42 | # Create buttons below the section 43 | # ------------------------------------------------------------------------------------------------------------------- 44 | 45 | att_img_btn=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\Photo.png") 46 | att_img_btn=att_img_btn.resize((250,250),Image.ADAPTIVE) 47 | self.att_img1=ImageTk.PhotoImage(att_img_btn) 48 | 49 | att_b1 = Button(bg_img,image=self.att_img1,cursor="hand2",command=self.linkedin) 50 | att_b1.place(x=350,y=120,width=250,height=250) 51 | 52 | att_b1_1 = Button(bg_img,text="Software Developer",command=self.linkedin,cursor="hand2",font=("tahoma",10,"bold"),bg="white",fg="navyblue") 53 | att_b1_1.place(x=350,y=370,width=250,height=50) 54 | 55 | 56 | # Creating Frame 57 | main_frame = Frame(bg_img,bd=2,bg="white") #bd mean border 58 | main_frame.place(x=600,y=120,width=550,height=300) 59 | # Right Label Frame 60 | right_frame = LabelFrame(main_frame,bd=2,bg="white",relief=RIDGE,text="Developer",font=("verdana",10,"bold"),fg="navyblue") 61 | right_frame.place(x=7,y=7,width=510,height=280) 62 | 63 | #label Name 64 | name_label=Label(right_frame,text="Name:",font=("verdana",12),bg="white") 65 | name_label.grid(row=0,column=0,padx=5,pady=12) 66 | #Name 67 | name=Label(right_frame,text="Md Nadeem Sarwar",font=("verdana",12,"bold"),bg="white", fg="navyblue",) 68 | name.grid(row=0,column=1,padx=5,pady=12,sticky=W) 69 | 70 | #label ID 71 | idstd_label=Label(right_frame,text="Course:",font=("verdana",12),bg="white") 72 | idstd_label.grid(row=1,column=0,padx=5,pady=12) 73 | #ID 74 | idstd=Label(right_frame,text="Btech(CSE)",font=("verdana",12,"bold"),bg="white", fg="navyblue",) 75 | idstd.grid(row=1,column=1,padx=5,pady=12,sticky=W) 76 | 77 | #label class 78 | classStd_label=Label(right_frame,text="Roll No:",font=("verdana",12),bg="white") 79 | classStd_label.grid(row=2,column=0,padx=5,pady=12) 80 | #class 81 | classStd=Label(right_frame,text="20SCSE1010767",font=("verdana",12,"bold"),bg="white",fg="navyblue",) 82 | classStd.grid(row=2,column=1,padx=5,pady=12,sticky=W) 83 | 84 | #label phone 85 | phone_label=Label(right_frame,text="Phone No:",font=("verdana",12),bg="white") 86 | phone_label.grid(row=3,column=0,padx=5,pady=12) 87 | #phone 88 | phone=Label(right_frame,text="85400003089",font=("verdana",12,"bold"),bg="white",fg="navyblue",) 89 | phone.grid(row=3,column=1,padx=5,pady=12,sticky=W) 90 | 91 | #label email 92 | email_label=Label(right_frame,text="Email:",font=("verdana",12),bg="white") 93 | email_label.grid(row=4,column=0,padx=5,pady=12) 94 | #email 95 | email=Label(right_frame,text="nadeemsarwar11612@gmail.com",font=("verdana",12,"bold"),bg="white",fg="navyblue",) 96 | email.grid(row=4,column=1,padx=5,pady=12,sticky=W) 97 | 98 | 99 | def linkedin(self): 100 | self.new = 1 101 | self.url = "https://www.linkedin.com/in/md-nadeem-sarwar-b564b919b/" 102 | webbrowser.open(self.url,new=self.new) 103 | 104 | 105 | if __name__ == "__main__": 106 | root=Tk() 107 | obj=Developer(root) 108 | root.mainloop() -------------------------------------------------------------------------------- /face_recognizer.py: -------------------------------------------------------------------------------- 1 | from tkinter import* 2 | from tkinter import ttk 3 | from PIL import Image, ImageTk 4 | from tkinter import messagebox 5 | import os 6 | import mysql.connector 7 | import cv2 8 | import numpy as np 9 | from time import strftime 10 | from datetime import datetime 11 | from sys import path 12 | 13 | class Face_Recognition: 14 | 15 | def __init__(self, root): 16 | self.root=root 17 | self.root.geometry("1530x790+0+0") 18 | self.root.title("face Recognition") 19 | 20 | title_lbl=Label(self.root,text="FACE RECOGNITION",font=("times new roman",35,"bold"),bg="white", fg="red") 21 | title_lbl.place(x=0,y=0,width=1530, height=45) 22 | #ist image 23 | img_top=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\det2.jpg") 24 | img_top=img_top.resize((650,700),Image.ADAPTIVE) 25 | self.photoimg_top=ImageTk.PhotoImage(img_top) 26 | 27 | f_lbl =Label(self.root,image=self.photoimg_top) 28 | f_lbl.place(x=0,y=55, width=650, height=700) 29 | #2nd Image 30 | img_bottom=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\image.jpg") 31 | img_bottom=img_bottom.resize((950,700),Image.ADAPTIVE) 32 | self.photoimg_bottom=ImageTk.PhotoImage(img_bottom) 33 | 34 | f_lbl =Label(self.root,image=self.photoimg_bottom) 35 | f_lbl.place(x=650,y=55, width=950, height=700) 36 | 37 | b1_1=Button(f_lbl, text="Face Recognition",command=self.face_recog, cursor="hand2",font=("times new roman",18,"bold"),bg="white", fg="red") 38 | b1_1.place(x=365, y=620, width=200, height=40) 39 | 40 | # #=====================Attendance=================== 41 | 42 | def mark_attendance(self,i,n,r): 43 | with open("attendance.csv","r+",newline="\n") as f: 44 | myDatalist=f.readlines() 45 | name_list=[] 46 | for line in myDatalist: 47 | entry=line.split((",")) 48 | name_list.append(entry[0]) 49 | 50 | if((i not in name_list)) and ((r not in name_list)) and ((n not in name_list)): 51 | now=datetime.now() 52 | d1=now.strftime("%d/%m/%Y") 53 | dtString=now.strftime("%H:%M:%S") 54 | f.writelines(f"\n{i}, {r}, {n}, {dtString}, {d1}, Present") 55 | 56 | 57 | #================face recognition================== 58 | def face_recog(self): 59 | def draw_boundray(img,classifier,scaleFactor,minNeighbors,color,text,clf): 60 | gray_image=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 61 | featuers=classifier.detectMultiScale(gray_image,scaleFactor,minNeighbors) 62 | coord=[] 63 | for (x,y,w,h) in featuers: 64 | cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),3) 65 | id,predict=clf.predict(gray_image[y:y+h,x:x+w]) 66 | confidence=int((100*(1-predict/300))) 67 | 68 | conn = mysql.connector.connect(host="localhost", username="root", password="Nadeem@786", database="face_recognizer",port=3306) 69 | cursor = conn.cursor() 70 | cursor.execute("select Student_id from student where Student_id="+str(id)) 71 | i=cursor.fetchone() 72 | # i="+".join(i) 73 | if i is not None: 74 | i = "+".join(i) 75 | 76 | 77 | cursor.execute("select Roll from student where Student_id="+str(id)) 78 | r=cursor.fetchone() 79 | # r="+".join(r) 80 | if r is not None: 81 | r = "+".join(r) 82 | 83 | 84 | cursor.execute("select Name from student where Student_id="+str(id)) 85 | n=cursor.fetchone() 86 | # n="+".join(n) 87 | if n is not None: 88 | n = "+".join(n) 89 | 90 | 91 | if confidence > 77: 92 | cv2.putText(img,f"Student_id:{i}",(x,y-80),cv2.FONT_HERSHEY_COMPLEX,0.8,(64,15,223),2) 93 | cv2.putText(img,f"Name:{n}",(x,y-55),cv2.FONT_HERSHEY_COMPLEX,0.8,(64,15,223),2) 94 | cv2.putText(img,f"Roll:{r}",(x,y-30),cv2.FONT_HERSHEY_COMPLEX,0.8,(64,15,223),2) 95 | self.mark_attendance(i,n,r) 96 | else: 97 | cv2.rectangle(img,(x,y),(x+w,y+h),(0,0,255),3) 98 | cv2.putText(img,"Unknown Face",(x,y-5),cv2.FONT_HERSHEY_COMPLEX,0.8,(255,255,0),3) 99 | 100 | coord=[x,y,w,y] 101 | 102 | return coord 103 | 104 | 105 | def recognize(img,clf,faceCascade): 106 | coord=draw_boundray(img,faceCascade,1.1,10,(255,25,255),"Face",clf) 107 | return img 108 | 109 | 110 | faceCascade=cv2.CascadeClassifier("haarcascade_frontalface_default.xml") 111 | clf=cv2.face.LBPHFaceRecognizer_create() 112 | clf.read("classifier.xml") 113 | 114 | videoCap=cv2.VideoCapture(0) 115 | 116 | while True: 117 | ret,img=videoCap.read() 118 | img=recognize(img,clf,faceCascade) 119 | 120 | cv2.imshow("Welcome To Face Recognition",img) 121 | 122 | # Press 'q' to exit the loop and close the window 123 | if cv2.waitKey(1) & 0xFF == ord('q'): 124 | break 125 | 126 | videoCap.release() 127 | cv2.destroyAllWindows() 128 | print("Window closed") 129 | 130 | if __name__ == "__main__": 131 | root=Tk() 132 | obj=Face_Recognition(root) 133 | root.mainloop() -------------------------------------------------------------------------------- /support.py: -------------------------------------------------------------------------------- 1 | # from tkinter import* 2 | # from tkinter import ttk 3 | # from PIL import Image, ImageTk 4 | # import os 5 | # from student import Student 6 | # import cv2 7 | # import webbrowser 8 | 9 | 10 | # class Helps: 11 | # def __init__(self,root): 12 | # self.root=root 13 | # self.root.geometry("1530x790+0+0") 14 | # self.root.title("Exit Window") 15 | 16 | # # This part is image labels setting start 17 | # # first header image 18 | # img=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\banner1.jpg") 19 | # img=img.resize((1530,230),Image.ADAPTIVE) 20 | # self.photoimg=ImageTk.PhotoImage(img) 21 | 22 | # # set image as lable 23 | # f_lb1 = Label(self.root,image=self.photoimg) 24 | # f_lb1.place(x=0,y=0,width=1530,height=230) 25 | 26 | # # backgorund image 27 | # bg1=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\bg2.jpg") 28 | # bg1=bg1.resize((1530,710),Image.ADAPTIVE) 29 | # self.photobg1=ImageTk.PhotoImage(bg1) 30 | 31 | # # set image as lable 32 | # bg_img = Label(self.root,image=self.photobg1) 33 | # bg_img.place(x=0,y=150,width=1530,height=710) 34 | 35 | 36 | # #title section 37 | # title_lb1 = Label(bg_img,text="Help & Support",font=("verdana",20,"bold"),bg="navyblue",fg="white") 38 | # title_lb1.place(x=0,y=0,width=1530,height=50) 39 | 40 | # # Create buttons below the section 41 | # # ------------------------------------------------------------------------------------------------------------------- 42 | # # student button 1 43 | # std_img_btn=Image.open(r"image\web.png") 44 | # std_img_btn=std_img_btn.resize((180,180),Image.ADAPTIVE) 45 | # self.std_img1=ImageTk.PhotoImage(std_img_btn) 46 | 47 | # std_b1 = Button(bg_img,command=self.website,image=self.std_img1,cursor="hand2") 48 | # std_b1.place(x=210,y=160,width=180,height=180) 49 | 50 | # std_b1_1 = Button(bg_img,command=self.website,text="Website",cursor="hand2",font=("tahoma",15,"bold"),bg="white",fg="navyblue") 51 | # std_b1_1.place(x=210,y=340,width=180,height=45) 52 | 53 | # # Detect Face button 2 54 | # det_img_btn=Image.open(r"image\fb.png") 55 | # det_img_btn=det_img_btn.resize((180,180),Image.ADAPTIVE) 56 | # self.det_img1=ImageTk.PhotoImage(det_img_btn) 57 | 58 | # det_b1 = Button(bg_img,command=self.facebook,image=self.det_img1,cursor="hand2",) 59 | # det_b1.place(x=440,y=160,width=180,height=180) 60 | 61 | # det_b1_1 = Button(bg_img,command=self.facebook,text="Facebook",cursor="hand2",font=("tahoma",15,"bold"),bg="white",fg="navyblue") 62 | # det_b1_1.place(x=440,y=340,width=180,height=45) 63 | 64 | # # Attendance System button 3 65 | # att_img_btn=Image.open(r"image\yt.png") 66 | # att_img_btn=att_img_btn.resize((180,180),Image.ADAPTIVE) 67 | # self.att_img1=ImageTk.PhotoImage(att_img_btn) 68 | 69 | # att_b1 = Button(bg_img,command=self.youtube,image=self.att_img1,cursor="hand2",) 70 | # att_b1.place(x=670,y=160,width=180,height=180) 71 | 72 | # att_b1_1 = Button(bg_img,command=self.youtube,text="Youtube",cursor="hand2",font=("tahoma",15,"bold"),bg="white",fg="navyblue") 73 | # att_b1_1.place(x=670,y=340,width=180,height=45) 74 | 75 | # # Help Support button 4 76 | # hlp_img_btn=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\gmail.png") 77 | # hlp_img_btn=hlp_img_btn.resize((180,180),Image.ADAPTIVE) 78 | # self.hlp_img1=ImageTk.PhotoImage(hlp_img_btn) 79 | 80 | # hlp_b1 = Button(bg_img,command=self.gmail,image=self.hlp_img1,cursor="hand2",) 81 | # hlp_b1.place(x=900,y=160,width=180,height=180) 82 | 83 | # hlp_b1_1 = Button(bg_img,command=self.gmail,text="Gmail",cursor="hand2",font=("tahoma",15,"bold"),bg="white",fg="navyblue") 84 | # hlp_b1_1.place(x=900,y=340,width=180,height=45) 85 | 86 | # # Help Support button 5 87 | # llis_img_btn=Image.open(r"image\linkedin.png") 88 | # llis_img_btn=llis_img_btn.resize((180,180),Image.ADAPTIVE) 89 | # self.llis_img1=ImageTk.PhotoImage(llis_img_btn) 90 | 91 | # llis_b1 = Button(bg_img,command=self.linkedin,image=self.llis_img1,cursor="hand2",) 92 | # llis_b1.place(x=1130,y=160,width=180,height=180) 93 | 94 | # llis_b1_1 = Button(bg_img,command=self.linkedin,text="Linkedin",cursor="hand2",font=("tahoma",15,"bold"),bg="white",fg="navyblue") 95 | # llis_b1_1.place(x=1130,y=340,width=180,height=45) 96 | 97 | 98 | # # create function for button 99 | 100 | 101 | # def website(self): 102 | # self.new = 1 103 | # self.url = "https://github.com/MdnadeemSarwar" 104 | # webbrowser.open(self.url,new=self.new) 105 | 106 | # def facebook(self): 107 | # self.new = 1 108 | # self.url = "https://www.facebook.com/nadeem.sarwar.79069/" 109 | # webbrowser.open(self.url,new=self.new) 110 | 111 | # def youtube(self): 112 | # self.new = 1 113 | # self.url = "https://www.youtube.com/@Careerhelpline" 114 | # webbrowser.open(self.url,new=self.new) 115 | 116 | # def gmail(self): 117 | # self.new = 1 118 | # self.url = "https://www.gmail.com" 119 | # webbrowser.open(self.url,new=self.new) 120 | 121 | # def linkedin(self): 122 | # self.new = 1 123 | # self.url = "https://www.linkedin.com/in/md-nadeem-sarwar-b564b919b/" 124 | # webbrowser.open(self.url,new=self.new) 125 | 126 | 127 | # if __name__ == "__main__": 128 | # root=Tk() 129 | # obj = Helps(root) 130 | # root.mainloop() 131 | 132 | -------------------------------------------------------------------------------- /Registers.py: -------------------------------------------------------------------------------- 1 | # from tkinter import* 2 | # from tkinter import ttk 3 | # from PIL import Image,ImageTk 4 | # from tkinter import messagebox 5 | # import mysql.connector 6 | # # from login import Login 7 | # class Register: 8 | # def __init__(self,root): 9 | # self.root=root 10 | # self.root.geometry("1530x790+0+0") 11 | # self.root.title("Registers Record") 12 | # self.root.configure(bg="#002B53") 13 | 14 | # # ============ Variables ================= 15 | # self.var_fname=StringVar() 16 | # self.var_lname=StringVar() 17 | # self.var_cnum=StringVar() 18 | # self.var_email=StringVar() 19 | # self.var_ssq=StringVar() 20 | # self.var_sa=StringVar() 21 | # self.var_pwd=StringVar() 22 | # self.var_cpwd=StringVar() 23 | # self.var_check=IntVar() 24 | 25 | 26 | # bg_image = Image.open("Image/student.jpg") 27 | # bg_image = bg_image.resize((1280, 720), Image.ADAPTIVE) # Resize the image to fit the window 28 | # bg_photo = ImageTk.PhotoImage(bg_image) 29 | 30 | # # Create a label for the background image 31 | # bg_label = Label(root, image=bg_photo) 32 | # bg_label.place(x=0, y=0, relwidth=1, relheight=1) 33 | 34 | 35 | # # Create a frame for content 36 | # frame = Frame(root, highlightbackground="lightgray", highlightthickness=2, bg="#F2F2F2") 37 | # frame.place(x=500, y=100, width=670, height=480) # Adjust the position and size of the frame as needed 38 | 39 | 40 | # get_str = Label(frame,text="Admin",font=("times new roman",20,"bold"),fg="#F2F2F2",bg="#002B53") 41 | # get_str.place(x=0,y=0,width=665,height=50) 42 | 43 | # #label1 44 | # fname =lb1= Label(frame,text="First Name:",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 45 | # fname.place(x=50,y=90) 46 | 47 | # #entry1 48 | # self.txtuser=ttk.Entry(frame,textvariable=self.var_fname,font=("times new roman",15,"bold")) 49 | # self.txtuser.place(x=50,y=120,width=270) 50 | 51 | 52 | # #label2 53 | # lname =lb1= Label(frame,text="Last Nmae:",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 54 | # lname.place(x=50,y=160) 55 | 56 | # #entry2 57 | # self.txtpwd=ttk.Entry(frame,textvariable=self.var_lname,font=("times new roman",15,"bold")) 58 | # self.txtpwd.place(x=50,y=190,width=270) 59 | 60 | # # ==================== section 2 -------- 2nd Columan=================== 61 | 62 | # #label1 63 | # cnum =lb1= Label(frame,text="Contact Info:",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 64 | # cnum.place(x=350,y=90) 65 | 66 | # #entry1 67 | # self.txtuser=ttk.Entry(frame,textvariable=self.var_cnum,font=("times new roman",15,"bold")) 68 | # self.txtuser.place(x=350,y=120,width=270) 69 | 70 | 71 | # #label2 72 | # email =lb1= Label(frame,text="Email:",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 73 | # email.place(x=350,y=160) 74 | 75 | # #entry2 76 | # self.txtpwd=ttk.Entry(frame,textvariable=self.var_email,font=("times new roman",15,"bold")) 77 | # self.txtpwd.place(x=350,y=190,width=270) 78 | 79 | # # ========================= Section 3 --- 1 Columan================= 80 | 81 | # #label1 82 | # ssq =lb1= Label(frame,text="Password:",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 83 | # ssq.place(x=50,y=230) 84 | 85 | # #Combo Box1 86 | # self.combo_security = ttk.Combobox(frame,textvariable=self.var_ssq,font=("times new roman",15,"bold"),state="readonly") 87 | # self.combo_security["values"]=("Select","Date of Birth","Nick Name","Previous School") 88 | # self.combo_security.current(0) 89 | # self.combo_security.place(x=50,y=260,width=270) 90 | 91 | # #label2 92 | # sa =lb1= Label(frame,text="Quiz:",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 93 | # sa.place(x=50,y=300) 94 | 95 | # #entry2 96 | # self.txtpwd=ttk.Entry(frame,textvariable=self.var_sa,font=("times new roman",15,"bold")) 97 | # self.txtpwd.place(x=50,y=330,width=270) 98 | 99 | # # ========================= Section 4-----Column 2============================= 100 | 101 | # #label1 102 | # pwd =lb1= Label(frame,text="Password:",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 103 | # pwd.place(x=350,y=230) 104 | 105 | # #entry1 106 | # self.txtuser=ttk.Entry(frame,textvariable=self.var_pwd,font=("times new roman",15,"bold")) 107 | # self.txtuser.place(x=350,y=260,width=270) 108 | 109 | 110 | # #label2 111 | # cpwd =lb1= Label(frame,text="Confirm Password:",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 112 | # cpwd.place(x=350,y=300) 113 | 114 | # #entry2 115 | # self.txtpwd=ttk.Entry(frame,textvariable=self.var_cpwd,font=("times new roman",15,"bold")) 116 | # self.txtpwd.place(x=350,y=330,width=270) 117 | 118 | # # Checkbutton 119 | # checkbtn = Checkbutton(frame,variable=self.var_check,text="Agree to the terms",font=("times new roman",13,"bold"),fg="#002B53",bg="#F2F2F2") 120 | # checkbtn.place(x=40,y=370,width=270) 121 | 122 | 123 | # # Creating Button Register 124 | # loginbtn=Button(frame,command=self.reg,text= "Register" ,font=("times new roman",15,"bold"),bd=0,relief=RIDGE,fg="#fff",bg="#002B53",activeforeground="white",activebackground="#007ACC") 125 | # loginbtn.place(x=50,y=410,width=270,height=35) 126 | 127 | # # Creating Button Login 128 | # loginbtn=Button(frame,text="Log in", font=("times new roman",15,"bold"),bd=0,relief=RIDGE,fg="#fff",bg="#002B53",activeforeground="white",activebackground="#007ACC") 129 | # loginbtn.place(x=350,y=410,width=270,height=35) 130 | 131 | 132 | 133 | 134 | # def reg(self): 135 | # if (self.var_fname.get()=="" or self.var_lname.get()=="" or self.var_cnum.get()=="" or self.var_email.get()=="" or self.var_ssq.get()=="Select" or self.var_sa.get()=="" or self.var_pwd.get()=="" or self.var_cpwd.get()==""): 136 | # messagebox.showerror("Error","All fields are required!") 137 | # elif(self.var_pwd.get() != self.var_cpwd.get()): 138 | # messagebox.showerror("Error","Please enter the same password and confirm password!") 139 | # elif(self.var_check.get()==0): 140 | # messagebox.showerror("Error","Please check the Terms and Conditions that have been agreed!") 141 | # else: 142 | # # messagebox.showinfo("Successfully","Successfully Register!") 143 | # try: 144 | # conn = mysql.connector.connect(user='root', password='Nadeem@786',host='localhost',database='face_recognizer',port=3306) 145 | # mycursor = conn.cursor() 146 | # query=("select * from regteach where email=%s") 147 | # value=(self.var_email.get(),) 148 | # mycursor.execute(query,value) 149 | # row=mycursor.fetchone() 150 | # if row!=None: 151 | # messagebox.showerror("Error","User already exists, please try a different Email") 152 | # else: 153 | # mycursor.execute("insert into regteach values(%s,%s,%s,%s,%s,%s,%s)",( 154 | # self.var_fname.get(), 155 | # self.var_lname.get(), 156 | # self.var_cnum.get(), 157 | # self.var_email.get(), 158 | # self.var_ssq.get(), 159 | # self.var_sa.get(), 160 | # self.var_pwd.get() 161 | # )) 162 | 163 | # conn.commit() 164 | # conn.close() 165 | # messagebox.showinfo("Success","Registration successful!",parent=self.root) 166 | # except Exception as es: 167 | # messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root) 168 | 169 | 170 | 171 | 172 | # if __name__ == "__main__": 173 | # root=Tk() 174 | # app=Register(root) 175 | # root.mainloop() 176 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from tkinter import* 2 | from tkinter import ttk 3 | from PIL import Image, ImageTk 4 | import os 5 | from student import Student 6 | from train import Train 7 | from face_recognizer import Face_Recognition 8 | from attendence import Attendance 9 | from support import Helps 10 | from login import Login 11 | from Registers import Register 12 | import tkinter 13 | from developer import Developer 14 | from time import strftime 15 | from datetime import datetime 16 | 17 | 18 | class Face_Recognition_System: 19 | def __init__(self,root): 20 | self.root=root 21 | self.root.geometry("1530x790+0+0") 22 | self.root.title("face Recognition System") 23 | 24 | #FIRST IMAGE 25 | 26 | img=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\Galgotias-University.jpg") 27 | img=img.resize((500,130),Image.ADAPTIVE) 28 | self.photoimg=ImageTk.PhotoImage(img) 29 | 30 | f_lbl =Label(self.root,image=self.photoimg) 31 | f_lbl.place(x=0,y=0, width=500, height=130) 32 | #SECOND IMAGE 33 | 34 | img1=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\facialrecognition.png") 35 | img1=img1.resize((500,130),Image.ADAPTIVE) 36 | self.photoimg1=ImageTk.PhotoImage(img1) 37 | 38 | f_lbl =Label(self.root,image=self.photoimg1) 39 | f_lbl.place(x=500,y=0, width=500, height=130) 40 | #THIRD IMAGE 41 | 42 | img2=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\gu.jpg") 43 | img2=img2.resize((500,130),Image.ADAPTIVE) 44 | self.photoimg2=ImageTk.PhotoImage(img2) 45 | 46 | f_lbl =Label(self.root,image=self.photoimg2) 47 | f_lbl.place(x=1000,y=0, width=550, height=130) 48 | 49 | #Baground IMAGE 50 | 51 | img3=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\bgs.jpg") 52 | img3=img3.resize((1530,710),Image.ADAPTIVE) 53 | self.photoimg3=ImageTk.PhotoImage(img3) 54 | 55 | bg_img=Label(self.root,image=self.photoimg3) 56 | bg_img.place(x=0,y=130, width=1530, height=710) 57 | 58 | title_lbl=Label(bg_img,text="FACE RECOGNITION ATTENDANCE SYSTEM SOFTWARE",font=("times new roman",30,"bold"),bg="white", fg="red") 59 | title_lbl.place(x=0,y=0,width=1530, height=50) 60 | 61 | ######## Time Update ################# 62 | def time(): 63 | string = strftime('%H:%M:%S %p') 64 | lbl.config(text = string) 65 | lbl.after(1000, time) 66 | 67 | lbl=Label(title_lbl,font=("times new roman",14,"bold"),bg="white", fg="black") 68 | lbl.place(x=0,y=0,width=110, height=50) 69 | time() 70 | 71 | 72 | # #student Bottom 73 | img4=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\sts.jpg") 74 | img4=img4.resize((220,220),Image.ADAPTIVE) 75 | self.photoimg4=ImageTk.PhotoImage(img4) 76 | 77 | b1=Button(bg_img, image=self.photoimg4,command=self.student_details,cursor="hand2") 78 | b1.place(x=200, y=100, width=220, height=220) 79 | 80 | b1_1=Button(bg_img, text="Student Details",command=self.student_details,cursor="hand2",font=("times new roman",15,"bold"),bg="darkblue", fg="white") 81 | b1_1.place(x=200, y=300, width=220, height=40) 82 | 83 | #Detection face button 84 | img5=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\facess.jpg") 85 | img5=img5.resize((220,220),Image.ADAPTIVE) 86 | self.photoimg5=ImageTk.PhotoImage(img5) 87 | 88 | b1=Button(bg_img,image=self.photoimg5,cursor="hand2",command=self.face_data) 89 | b1.place(x=500, y=100, width=220, height=220) 90 | 91 | b1_1=Button(bg_img, text="Face Detector", cursor="hand2",command=self.face_data, font=("times new roman",15,"bold"),bg="darkblue", fg="white") 92 | b1_1.place(x=500, y=300, width=220, height=40) 93 | 94 | #Attendance button 95 | img6=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\att.jpg") 96 | img6=img6.resize((220,220),Image.ADAPTIVE) 97 | self.photoimg6=ImageTk.PhotoImage(img6) 98 | 99 | b1=Button(bg_img,image=self.photoimg6,cursor="hand2",command=self.attendance_data) 100 | b1.place(x=800, y=100, width=220, height=220) 101 | 102 | b1_1=Button(bg_img, text="Attendance", cursor="hand2",command=self.attendance_data, font=("times new roman",15,"bold"),bg="darkblue", fg="white") 103 | b1_1.place(x=800, y=300, width=220, height=40) 104 | 105 | 106 | #HelpDesk button 107 | img7=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\help-desk.png") 108 | img7=img7.resize((220,220),Image.ADAPTIVE) 109 | self.photoimg7=ImageTk.PhotoImage(img7) 110 | 111 | b1=Button(bg_img,image=self.photoimg7,cursor="hand2",command=self.help_data) 112 | b1.place(x=1100, y=100, width=220, height=220) 113 | 114 | b1_1=Button(bg_img, text="Help Desk", command=self.help_data, cursor="hand2",font=("times new roman",15,"bold"),bg="darkblue", fg="white") 115 | b1_1.place(x=1100, y=300, width=220, height=40) 116 | 117 | #Train face button 118 | img8=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\train.jpg") 119 | img8=img8.resize((220,220),Image.ADAPTIVE) 120 | self.photoimg8=ImageTk.PhotoImage(img8) 121 | 122 | b1=Button(bg_img,image=self.photoimg8,cursor="hand2",command=self.train_data) 123 | b1.place(x=200, y=380, width=220, height=220) 124 | 125 | b1_1=Button(bg_img, text="Train Data", cursor="hand2",command=self.train_data, font=("times new roman",15,"bold"),bg="darkblue", fg="white") 126 | b1_1.place(x=200, y=580, width=220, height=40) 127 | 128 | #Photos face button 129 | img9=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\facede.jpg") 130 | img9=img9.resize((220,220),Image.ADAPTIVE) 131 | self.photoimg9=ImageTk.PhotoImage(img9) 132 | 133 | b1=Button(bg_img,image=self.photoimg9,cursor="hand2",command=self.open_img) 134 | b1.place(x=500, y=380, width=220, height=220) 135 | 136 | b1_1=Button(bg_img, text="Photos", cursor="hand2",command=self.open_img,font=("times new roman",15,"bold"),bg="darkblue", fg="white") 137 | b1_1.place(x=500, y=580, width=220, height=40) 138 | 139 | #Developer button 140 | img10=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\deve.jpg") 141 | img10=img10.resize((220,220),Image.ADAPTIVE) 142 | self.photoimg10=ImageTk.PhotoImage(img10) 143 | 144 | b1=Button(bg_img,image=self.photoimg10,cursor="hand2",command=self.developer_data) 145 | b1.place(x=800, y=380, width=220, height=220) 146 | 147 | b1_1=Button(bg_img, text="Developer",command=self.developer_data, cursor="hand2", font=("times new roman",15,"bold"),bg="darkblue", fg="white") 148 | b1_1.place(x=800, y=580, width=220, height=40) 149 | 150 | #Exit button 151 | img11=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\exit.png") 152 | img11=img11.resize((220,220),Image.ADAPTIVE) 153 | self.photoimg11=ImageTk.PhotoImage(img11) 154 | 155 | b1=Button(bg_img,image=self.photoimg11,cursor="hand2",command=self.exitkardu) 156 | b1.place(x=1100, y=380, width=220, height=220) 157 | 158 | b1_1=Button(bg_img, text="Exit", cursor="hand2",command=self.exitkardu, font=("times new roman",15,"bold"),bg="darkblue", fg="white") 159 | b1_1.place(x=1100, y=580, width=220, height=40) 160 | 161 | ########################## Exit Window #################### 162 | def open_img(self): 163 | os.startfile("data") 164 | 165 | def exitkardu(self): 166 | self.exitkardu=tkinter.messagebox.askyesno("Face Recognition","Are you sure to exit this project",parent=self.root) 167 | if self.exitkardu >0: 168 | self.root.destroy() 169 | else: 170 | return 171 | 172 | ############################ Function Botton ################# 173 | 174 | def student_details(self): 175 | self.new_window=Toplevel(self.root) 176 | self.app=Student(self.new_window) 177 | 178 | def train_data(self): 179 | self.new_window=Toplevel(self.root) 180 | self.app=Train(self.new_window) 181 | 182 | def face_data(self): 183 | self.new_window=Toplevel(self.root) 184 | self.app=Face_Recognition(self.new_window) 185 | 186 | def attendance_data(self): 187 | self.new_window=Toplevel(self.root) 188 | self.app=Attendance(self.new_window) 189 | 190 | def developer_data(self): 191 | self.new_window=Toplevel(self.root) 192 | self.app=Developer(self.new_window) 193 | 194 | def help_data(self): 195 | self.new_window=Toplevel(self.root) 196 | self.app=Helps(self.new_window) 197 | 198 | 199 | if __name__ == "__main__": 200 | root=Tk() 201 | obj = Face_Recognition_System(root) 202 | root.mainloop() 203 | 204 | 205 | -------------------------------------------------------------------------------- /login.py: -------------------------------------------------------------------------------- 1 | import os 2 | from tkinter import* 3 | from tkinter import ttk 4 | from PIL import Image, ImageTk 5 | from face_recognizer import Face_Recognition 6 | from student import Student 7 | from train import Train 8 | from attendence import Attendance 9 | from developer import Developer 10 | from support import Helps 11 | from Registers import Register 12 | import tkinter 13 | # import tkinter as tk 14 | from time import strftime 15 | # from datetime import datetimes 16 | from tkinter import messagebox 17 | import cv2 18 | import mysql.connector 19 | import numpy as np 20 | 21 | class Login: 22 | 23 | def __init__(self,root): 24 | self.root=root 25 | self.root.geometry("1530x790+0+0") 26 | self.root.title("Registers Record") 27 | # self.root.configure(bg="#002B53") 28 | 29 | # Background colr 30 | left_lbl = Label(self.root, bd=0) 31 | left_lbl.place(x=0, y=0, relheight=1, width=600) 32 | 33 | right_lbl = Label(self.root, bd=0) 34 | right_lbl.place(x=600, y=0, relheight=1, relwidth=1) 35 | 36 | 37 | # Frame 38 | login_frame = Frame(self.root, bg="white") 39 | login_frame.place(x=350, y=100, width=800, height=500) 40 | 41 | title = Label(login_frame, text="ADMIN LOGIN!", font=("times new roman", 30, "bold"), bg="white", fg="navyblue") 42 | title.place(x=305, y=50) 43 | 44 | #variable 45 | self.var_ssq=StringVar() 46 | self.var_sa=StringVar() 47 | self.var_pwd=StringVar() 48 | 49 | email = Label(login_frame, text="Email", font=("times new roman", 18, "bold"), bg="white", fg="navyblue").place(x=250, y=150) 50 | self.txtuser = Entry(login_frame, font=("times new roman", 15), bg="lightgray") 51 | self.txtuser.place(x=250, y=180, width=350, height=35) 52 | 53 | pass_ = Label(login_frame, text="Password", font=("times new roman", 18, "bold"), bg="white", fg="navyblue").place(x=250, y=250) 54 | self.txtpwd = Entry(login_frame, font=("times new roman", 15), bg="lightgray") 55 | self.txtpwd.place(x=250, y=280, width=350, height=35) 56 | 57 | btn_reg = Button(login_frame, cursor="hand2", command=self.reg, text="Register an account", font=("times new roman", 14), bg="white", bd=0, fg="navyblue").place(x=250, y=330) 58 | 59 | btn_forgetpwd = Button(login_frame, cursor="hand2", command=self.forget_pwd, text="Forget password", font=("times new roman", 14), bg="white", bd=0, fg="navyblue").place(x=500, y=330) 60 | 61 | btn_login = Button(login_frame, text="Login", command=self.login, font=("times new roman", 20, "bold"), fg="white", cursor="hand2", bg="navyblue").place(x=250, y=380, width=180, height=40) 62 | 63 | 64 | # THis function is for open register window 65 | def reg(self): 66 | self.new_window=Toplevel(self.root) 67 | self.app=Register(self.new_window) 68 | # self.new_window.state('zoomed') 69 | 70 | # THis function is for open login frame 71 | def login(self): 72 | if (self.txtuser.get()=="" or self.txtpwd.get()==""): 73 | messagebox.showerror("Error", "All fields are required!") 74 | elif(self.txtuser.get()=="admin" and self.txtpwd.get()=="admin"): 75 | messagebox.showinfo("Sussessfully", "Welcome to the Facial Recognition Attendance Management System") 76 | else: 77 | # messagebox.showerror("Error","Please Check Username or Password !") 78 | conn = mysql.connector.connect(user='root', password='Nadeem@786',host='localhost',database='face_recognizer',port=3306) 79 | mycursor = conn.cursor() 80 | mycursor.execute("select * from regteach where email=%s and pwd=%s",( 81 | self.txtuser.get(), 82 | self.txtpwd.get() 83 | )) 84 | row=mycursor.fetchone() 85 | if row==None: 86 | messagebox.showerror("Error", "Invalid Email and password!") 87 | else: 88 | open_min=messagebox.askyesno("Admin","Admin access only") 89 | if open_min>0: 90 | self.new_window=Toplevel(self.root) 91 | self.app=Face_Recognition_System(self.new_window) 92 | else: 93 | if not open_min: 94 | return 95 | conn.commit() 96 | conn.close() 97 | #=======================Reset Passowrd Function============================= 98 | def reset_pass(self): 99 | if self.var_ssq.get()=="Select": 100 | messagebox.showerror("Error","Security question!",parent=self.root2) 101 | elif(self.var_sa.get()==""): 102 | messagebox.showerror("Error", "Please enter your Email ID to reset your password!",parent=self.root2) 103 | elif(self.var_pwd.get()==""): 104 | messagebox.showerror("Error", "Please enter your Email ID to reset your password!",parent=self.root2) 105 | else: 106 | conn = mysql.connector.connect(user='root', password='Nadeem@786',host='localhost',database='face_recognizer',port=3306) 107 | mycursor = conn.cursor() 108 | query=("select * from regteach where email=%s and ss_que=%s and s_ans=%s") 109 | value=(self.txtuser.get(),self.var_ssq.get(),self.var_sa.get()) 110 | mycursor.execute(query,value) 111 | row=mycursor.fetchone() 112 | if row==None: 113 | messagebox.showerror("Error","Please enter the correct answer",parent=self.root2) 114 | else: 115 | query=("update regteach set pwd=%s where email=%s") 116 | value=(self.var_pwd.get(),self.txtuser.get()) 117 | mycursor.execute(query,value) 118 | 119 | conn.commit() 120 | conn.close() 121 | messagebox.showinfo("Info","Success! Your password has been reset.",parent=self.root2) 122 | 123 | 124 | 125 | 126 | # =====================Forget window========================================= 127 | def forget_pwd(self): 128 | if self.txtuser.get()=="": 129 | messagebox.showerror("Error","Reset your password!") 130 | else: 131 | conn = mysql.connector.connect(user='root', password="Nadeem@786",host='localhost',database='face_recognizer',port=3306) 132 | mycursor = conn.cursor() 133 | query=("select * from regteach where email=%s") 134 | value=(self.txtuser.get(),) 135 | mycursor.execute(query,value) 136 | row=mycursor.fetchone() 137 | # print(row) 138 | 139 | if row==None: 140 | messagebox.showerror("Error","Please enter a valid email ID!") 141 | else: 142 | conn.close() 143 | self.root2=Toplevel() 144 | self.root2.title( "Forgot password") 145 | self.root2.geometry("350x450+80+120") 146 | l=Label(self.root2,text="Forgot password",font=("times new roman",25,"bold"),fg="#fff",bg="#002B53") 147 | l.place(x=0,y=10,relwidth=1) 148 | # -------------------fields------------------- 149 | #label1 150 | ssq =lb1= Label(self.root2,text="Select security question",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 151 | ssq.place(x=45,y=80) 152 | 153 | #Combo Box1 154 | self.combo_security = ttk.Combobox(self.root2,textvariable=self.var_ssq,font=("times new roman",15,"bold"),state="readonly") 155 | self.combo_security["values"]=("Select","Date of Birth","Nick Name","Previous School") 156 | self.combo_security.current(0) 157 | self.combo_security.place(x=45,y=110,width=270) 158 | 159 | 160 | #label2 161 | sa =lb1= Label(self.root2,text="Answer:",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 162 | sa.place(x=45,y=150) 163 | 164 | #entry2 165 | self.txtpwd=ttk.Entry(self.root2,textvariable=self.var_sa,font=("times new roman",15,"bold")) 166 | self.txtpwd.place(x=45,y=180,width=270) 167 | 168 | #label2 169 | new_pwd =lb1= Label(self.root2,text= "New password:",font=("times new roman",15,"bold"),fg="#002B53",bg="#F2F2F2") 170 | new_pwd.place(x=45,y=220) 171 | 172 | #entry2 173 | self.new_pwd=ttk.Entry(self.root2,textvariable=self.var_pwd,font=("times new roman",15,"bold")) 174 | self.new_pwd.place(x=45,y=250,width=270) 175 | 176 | # Creating Button New Password 177 | loginbtn=Button(self.root2,command=self.reset_pass,text= "Reset password",font=("times new roman",15,"bold"),bd=0,relief=RIDGE,fg="#fff",bg="#002B53",activeforeground="white",activebackground="#007ACC") 178 | loginbtn.place(x=45,y=300,width=270,height=35) 179 | 180 | 181 | class Face_Recognition_System: 182 | def __init__(self,root): 183 | self.root=root 184 | self.root.geometry("1530x790+0+0") 185 | self.root.title("face Recognition System") 186 | 187 | #FIRST IMAGE 188 | 189 | img=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\Galgotias-University.jpg") 190 | img=img.resize((500,130),Image.ADAPTIVE) 191 | self.photoimg=ImageTk.PhotoImage(img) 192 | 193 | f_lbl =Label(self.root,image=self.photoimg) 194 | f_lbl.place(x=0,y=0, width=500, height=130) 195 | #SECOND IMAGE 196 | 197 | img1=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\facialrecognition.png") 198 | img1=img1.resize((500,130),Image.ADAPTIVE) 199 | self.photoimg1=ImageTk.PhotoImage(img1) 200 | 201 | f_lbl =Label(self.root,image=self.photoimg1) 202 | f_lbl.place(x=500,y=0, width=500, height=130) 203 | #THIRD IMAGE 204 | 205 | img2=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\gu.jpg") 206 | img2=img2.resize((500,130),Image.ADAPTIVE) 207 | self.photoimg2=ImageTk.PhotoImage(img2) 208 | 209 | f_lbl =Label(self.root,image=self.photoimg2) 210 | f_lbl.place(x=1000,y=0, width=550, height=130) 211 | 212 | #Baground IMAGE 213 | 214 | img3=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\bgs.jpg") 215 | img3=img3.resize((1530,710),Image.ADAPTIVE) 216 | self.photoimg3=ImageTk.PhotoImage(img3) 217 | 218 | bg_img=Label(self.root,image=self.photoimg3) 219 | bg_img.place(x=0,y=130, width=1530, height=710) 220 | 221 | title_lbl=Label(bg_img,text="FACE RECOGNITION ATTENDANCE SYSTEM SOFTWARE",font=("times new roman",30,"bold"),bg="white", fg="red") 222 | title_lbl.place(x=0,y=0,width=1530, height=50) 223 | 224 | ######## Time Update ################# 225 | 226 | 227 | 228 | # #student Bottom 229 | img4=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\sts.jpg") 230 | img4=img4.resize((220,220),Image.ADAPTIVE) 231 | self.photoimg4=ImageTk.PhotoImage(img4) 232 | 233 | b1=Button(bg_img, image=self.photoimg4,command=self.student_details,cursor="hand2") 234 | b1.place(x=200, y=100, width=220, height=220) 235 | 236 | b1_1=Button(bg_img, text="Student Details",command=self.student_details,cursor="hand2",font=("times new roman",15,"bold"),bg="darkblue", fg="white") 237 | b1_1.place(x=200, y=300, width=220, height=40) 238 | 239 | #Detection face button 240 | img5=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\facess.jpg") 241 | img5=img5.resize((220,220),Image.ADAPTIVE) 242 | self.photoimg5=ImageTk.PhotoImage(img5) 243 | 244 | b1=Button(bg_img,image=self.photoimg5,cursor="hand2",command=self.face_data) 245 | b1.place(x=500, y=100, width=220, height=220) 246 | 247 | b1_1=Button(bg_img, text="Face Detector", cursor="hand2",command=self.face_data, font=("times new roman",15,"bold"),bg="darkblue", fg="white") 248 | b1_1.place(x=500, y=300, width=220, height=40) 249 | 250 | #Attendance button 251 | img6=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\att.jpg") 252 | img6=img6.resize((220,220),Image.ADAPTIVE) 253 | self.photoimg6=ImageTk.PhotoImage(img6) 254 | 255 | b1=Button(bg_img,image=self.photoimg6,cursor="hand2",command=self.attendance_data) 256 | b1.place(x=800, y=100, width=220, height=220) 257 | 258 | b1_1=Button(bg_img, text="Attendance", cursor="hand2",command=self.attendance_data, font=("times new roman",15,"bold"),bg="darkblue", fg="white") 259 | b1_1.place(x=800, y=300, width=220, height=40) 260 | 261 | 262 | #HelpDesk button 263 | img7=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\help-desk.png") 264 | img7=img7.resize((220,220),Image.ADAPTIVE) 265 | self.photoimg7=ImageTk.PhotoImage(img7) 266 | 267 | b1=Button(bg_img,image=self.photoimg7,cursor="hand2",command=self.help_data) 268 | b1.place(x=1100, y=100, width=220, height=220) 269 | 270 | b1_1=Button(bg_img, text="Help Desk", command=self.help_data, cursor="hand2",font=("times new roman",15,"bold"),bg="darkblue", fg="white") 271 | b1_1.place(x=1100, y=300, width=220, height=40) 272 | 273 | #Train face button 274 | img8=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\train.jpg") 275 | img8=img8.resize((220,220),Image.ADAPTIVE) 276 | self.photoimg8=ImageTk.PhotoImage(img8) 277 | 278 | b1=Button(bg_img,image=self.photoimg8,cursor="hand2",command=self.train_data) 279 | b1.place(x=200, y=380, width=220, height=220) 280 | 281 | b1_1=Button(bg_img, text="Train Data", cursor="hand2",command=self.train_data, font=("times new roman",15,"bold"),bg="darkblue", fg="white") 282 | b1_1.place(x=200, y=580, width=220, height=40) 283 | 284 | #Photos face button 285 | img9=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\facede.jpg") 286 | img9=img9.resize((220,220),Image.ADAPTIVE) 287 | self.photoimg9=ImageTk.PhotoImage(img9) 288 | 289 | b1=Button(bg_img,image=self.photoimg9,cursor="hand2",command=self.open_img) 290 | b1.place(x=500, y=380, width=220, height=220) 291 | 292 | b1_1=Button(bg_img, text="Photos", cursor="hand2",command=self.open_img,font=("times new roman",15,"bold"),bg="darkblue", fg="white") 293 | b1_1.place(x=500, y=580, width=220, height=40) 294 | 295 | #Developer button 296 | img10=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\deve.jpg") 297 | img10=img10.resize((220,220),Image.ADAPTIVE) 298 | self.photoimg10=ImageTk.PhotoImage(img10) 299 | 300 | b1=Button(bg_img,image=self.photoimg10,cursor="hand2",command=self.developer_data) 301 | b1.place(x=800, y=380, width=220, height=220) 302 | 303 | b1_1=Button(bg_img, text="Developer",command=self.developer_data, cursor="hand2", font=("times new roman",15,"bold"),bg="darkblue", fg="white") 304 | b1_1.place(x=800, y=580, width=220, height=40) 305 | 306 | #Exit button 307 | img11=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\exit.png") 308 | img11=img11.resize((220,220),Image.ADAPTIVE) 309 | self.photoimg11=ImageTk.PhotoImage(img11) 310 | 311 | b1=Button(bg_img,image=self.photoimg11,cursor="hand2",command=self.exitkardu) 312 | b1.place(x=1100, y=380, width=220, height=220) 313 | 314 | b1_1=Button(bg_img, text="Exit", cursor="hand2",command=self.exitkardu, font=("times new roman",15,"bold"),bg="darkblue", fg="white") 315 | b1_1.place(x=1100, y=580, width=220, height=40) 316 | 317 | ####################### Exit Window #################### 318 | def open_img(self): 319 | os.startfile("data") 320 | 321 | def exitkardu(self): 322 | self.exitkardu=tkinter.messagebox.askyesno("Face Recognition","Are you sure to exit this project",parent=self.root) 323 | if self.exitkardu >0: 324 | self.root.destroy() 325 | else: 326 | return 327 | ############################ Function Botton ################# 328 | 329 | def student_details(self): 330 | self.new_window=Toplevel(self.root) 331 | self.app=Student(self.new_window) 332 | 333 | def train_data(self): 334 | self.new_window=Toplevel(self.root) 335 | self.app=Train(self.new_window) 336 | 337 | def face_data(self): 338 | self.new_window=Toplevel(self.root) 339 | self.app=Face_Recognition(self.new_window) 340 | 341 | def attendance_data(self): 342 | self.new_window=Toplevel(self.root) 343 | self.app=Attendance(self.new_window) 344 | 345 | def developer_data(self): 346 | self.new_window=Toplevel(self.root) 347 | self.app=Developer(self.new_window) 348 | 349 | def help_data(self): 350 | self.new_window=Toplevel(self.root) 351 | self.app=Helps(self.new_window) 352 | 353 | # def reg(self): 354 | # self.new_window=Toplevel(self.root) 355 | # self.app=Register(self.new_window) 356 | 357 | 358 | if __name__ == "__main__": 359 | root=Tk() 360 | app=Login(root) 361 | root.mainloop() 362 | -------------------------------------------------------------------------------- /attendence.py: -------------------------------------------------------------------------------- 1 | from sys import path 2 | from tkinter import* 3 | from tkinter import ttk 4 | from PIL import Image,ImageTk 5 | import os 6 | import mysql.connector 7 | import cv2 8 | import numpy as np 9 | from tkinter import messagebox 10 | from time import strftime 11 | from datetime import datetime 12 | import csv 13 | from tkinter import filedialog 14 | 15 | #Global variable for importCsv Function 16 | 17 | mydata=[] 18 | class Attendance: 19 | def __init__(self,root): 20 | self.root=root 21 | self.root.geometry("1530x790+0+0") 22 | self.root.title("Attendance Record") 23 | 24 | #-----------Variables------------------- 25 | self.var_id=StringVar() 26 | self.var_roll=StringVar() 27 | self.var_name=StringVar() 28 | self.var_dep=StringVar() 29 | self.var_time=StringVar() 30 | self.var_date=StringVar() 31 | self.var_attend=StringVar() 32 | 33 | # This part is image labels setting start 34 | # first header image 35 | img=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\att.jpg") 36 | img=img.resize((1530,430),Image.ADAPTIVE) 37 | self.photoimg=ImageTk.PhotoImage(img) 38 | 39 | # set image as lable 40 | f_lb1 = Label(self.root,image=self.photoimg) 41 | f_lb1.place(x=0,y=0,width=1530,height=430) 42 | 43 | # backgorund image 44 | bg1=Image.open(r"C:\Users\caree\Desktop\Face Reco\Image\student.jpg") 45 | bg1=bg1.resize((1530,540),Image.ADAPTIVE) 46 | self.photobg1=ImageTk.PhotoImage(bg1) # set image as lable 47 | bg_img = Label(self.root,image=self.photobg1) 48 | bg_img.place(x=0,y=145,width=1530,height=540) 49 | 50 | 51 | #title section 52 | title_lb1 = Label(bg_img,text="ATTENDANCE DETAILS",font=("verdana",20,"bold"),bg="navyblue",fg="white") 53 | title_lb1.place(x=0,y=0,width=1530,height=60) 54 | 55 | #========================Section Creating================================== 56 | 57 | # Creating Frame 58 | main_frame = Frame(bg_img,bd=2,bg="white") #bd mean border 59 | main_frame.place(x=0,y=60,width=1530,height=480) 60 | 61 | # Left Label Frame 62 | left_frame = LabelFrame(main_frame,bd=2,bg="white",relief=RIDGE,text="Students",font=("verdana",12,"bold"),fg="navyblue") 63 | left_frame.place(x=100,y=10,width=645,height=480) 64 | 65 | 66 | 67 | # ==================================Text boxes and Combo Boxes==================== 68 | 69 | #Student id 70 | attendanceID_label = Label(left_frame,text="AttendenceID:",font=("verdana",12,"bold"),fg="navyblue",bg="white") 71 | attendanceID_label.grid(row=0,column=0,padx=5,pady=5,sticky=W) 72 | 73 | attendanceID_entry = ttk.Entry(left_frame,textvariable=self.var_id,width=15,font=("verdana",12,"bold")) 74 | attendanceID_entry.grid(row=0,column=1,padx=5,pady=5,sticky=W) 75 | 76 | #Studnet Name 77 | student_name_label = Label(left_frame,text="Name:",font=("verdana",12,"bold"),fg="navyblue",bg="white") 78 | student_name_label.grid(row=1,column=0,padx=5,pady=5,sticky=W) 79 | 80 | student_name_entry = ttk.Entry(left_frame,textvariable=self.var_name,width=15,font=("verdana",12,"bold")) 81 | student_name_entry.grid(row=1,column=1,padx=5,pady=5,sticky=W) 82 | 83 | #Student Roll 84 | roll_label = Label(left_frame,text="Roll:",font=("verdana",12,"bold"),fg="navyblue",bg="white") 85 | roll_label.grid(row=0,column=2,padx=5,pady=5,sticky=W) 86 | 87 | student_roll_entry = ttk.Entry(left_frame,textvariable=self.var_roll,width=15,font=("verdana",12,"bold")) 88 | student_roll_entry.grid(row=0,column=3,padx=5,pady=5,sticky=W) 89 | 90 | # #Department 91 | # dep_label = Label(left_frame,text="Department:",font=("verdana",12,"bold"),fg="navyblue",bg="white") 92 | # dep_label.grid(row=1,column=2,padx=5,pady=5,sticky=W) 93 | 94 | # dep_entry = ttk.Entry(left_frame,textvariable=self.var_dep,width=15,font=("verdana",12,"bold")) 95 | # dep_entry.grid(row=1,column=3,padx=5,pady=5,sticky=W) 96 | 97 | #time 98 | timeLabel = Label(left_frame,text="Time:",font=("verdana",12,"bold"),fg="navyblue",bg="white") 99 | timeLabel.grid(row=1,column=2,padx=5,pady=5,sticky=W) 100 | 101 | time_entry = ttk.Entry(left_frame,textvariable=self.var_time,width=15,font=("verdana",12,"bold")) 102 | time_entry.grid(row=1,column=3,padx=5,pady=5,sticky=W) 103 | 104 | #Date 105 | dateLabel = Label(left_frame,text="Date:",font=("verdana",12,"bold"),fg="navyblue",bg="white") 106 | dateLabel.grid(row=2,column=0,padx=5,pady=5,sticky=W) 107 | 108 | date_entry = ttk.Entry(left_frame,textvariable=self.var_date,width=15,font=("verdana",12,"bold")) 109 | date_entry.grid(row=2,column=1,padx=5,pady=5,sticky=W) 110 | 111 | #Attendance 112 | attendanceLabel = Label(left_frame,text="Attend:",font=("verdana",12,"bold"),fg="navyblue",bg="white") 113 | attendanceLabel.grid(row=2,column=2,padx=5,pady=5,sticky=W) 114 | 115 | attend_combo=ttk.Combobox(left_frame,textvariable=self.var_attend,width=13,font=("verdana",12,"bold"),state="readonly") 116 | attend_combo["values"]=("Present","Absent") 117 | attend_combo.current(0) 118 | attend_combo.grid(row=2,column=3,padx=5,pady=5,sticky=W) 119 | 120 | # # ===============================Table Sql Data View========================== 121 | table_frame = Frame(left_frame,bd=2,bg="white",relief=RIDGE) 122 | table_frame.place(x=10,y=100,width=635,height=280) 123 | 124 | #scroll bar 125 | scroll_x = ttk.Scrollbar(table_frame,orient=HORIZONTAL) 126 | scroll_y = ttk.Scrollbar(table_frame,orient=VERTICAL) 127 | 128 | #create table 129 | self.attendanceReport_left = ttk.Treeview(table_frame,column=("ID","Roll_No","Name","Time","Date","Attend"),xscrollcommand=scroll_x.set,yscrollcommand=scroll_y.set) 130 | 131 | scroll_x.pack(side=BOTTOM,fill=X) 132 | scroll_y.pack(side=RIGHT,fill=Y) 133 | scroll_x.config(command=self.attendanceReport_left.xview) 134 | scroll_y.config(command=self.attendanceReport_left.yview) 135 | 136 | self.attendanceReport_left.heading("ID",text="ID") 137 | self.attendanceReport_left.heading("Roll_No",text="Roll") 138 | self.attendanceReport_left.heading("Name",text="Name") 139 | self.attendanceReport_left.heading("Time",text="Time") 140 | self.attendanceReport_left.heading("Date",text="Date") 141 | self.attendanceReport_left.heading("Attend",text="Attend") 142 | self.attendanceReport_left["show"]="headings" 143 | 144 | 145 | # # Set Width of Colums 146 | self.attendanceReport_left.column("ID",width=100) 147 | self.attendanceReport_left.column("Roll_No",width=100) 148 | self.attendanceReport_left.column("Name",width=100) 149 | self.attendanceReport_left.column("Time",width=100) 150 | self.attendanceReport_left.column("Date",width=100) 151 | self.attendanceReport_left.column("Attend",width=100) 152 | 153 | self.attendanceReport_left.pack(fill=BOTH,expand=1) 154 | self.attendanceReport_left.bind("",self.get_cursor_left) 155 | 156 | 157 | # # =========================button section======================== 158 | 159 | #Button Frame 160 | btn_frame = Frame(left_frame,bg="white",relief=RIDGE) 161 | btn_frame.place(x=10,y=375,width=635,height=40) 162 | 163 | #Improt button 164 | save_btn=Button(btn_frame,command=self.importCsv,text="Import CSV",width=12,font=("verdana",12,"bold"),fg="white",bg="navyblue") 165 | save_btn.grid(row=0,column=0,padx=6,pady=10,sticky=W) 166 | 167 | #Exprot button 168 | update_btn=Button(btn_frame,command=self.exportCsv,text="Export CSV",width=12,font=("verdana",12,"bold"),fg="white",bg="navyblue") 169 | update_btn.grid(row=0,column=1,padx=6,pady=8,sticky=W) 170 | 171 | #Update button ###*****command=self.action add hoga 172 | del_btn=Button(btn_frame,text="Update",command=self.action,width=12,font=("verdana",12,"bold"),fg="white",bg="navyblue") 173 | del_btn.grid(row=0,column=2,padx=6,pady=10,sticky=W) 174 | 175 | #reset button 176 | reset_btn=Button(btn_frame,command=self.reset_data,text="Reset",width=12,font=("verdana",12,"bold"),fg="white",bg="navyblue") 177 | reset_btn.grid(row=0,column=3,padx=6,pady=10,sticky=W) 178 | 179 | 180 | 181 | # # Right section======================================================= 182 | 183 | # Right Label Frame 184 | right_frame = LabelFrame(main_frame,bd=2,bg="white",relief=RIDGE,text="Details",font=("Attendence Details",12,"bold"),fg="navyblue") 185 | right_frame.place(x=780,y=10,width=660,height=480) 186 | 187 | 188 | # # -----------------------------Table Frame------------------------------------------------- 189 | #Table Frame 190 | #Searching System in Right Label Frame 191 | table_frame = Frame(right_frame,bd=2,bg="white",relief=RIDGE) 192 | table_frame.place(x=10,y=70,width=660,height=360) 193 | 194 | #scroll bar 195 | scroll_x = ttk.Scrollbar(table_frame,orient=HORIZONTAL) 196 | scroll_y = ttk.Scrollbar(table_frame,orient=VERTICAL) 197 | 198 | # #create table 199 | self.attendanceReport = ttk.Treeview(table_frame,column=("ID","Roll_No", "Name","Time","Date","Attend"),xscrollcommand=scroll_x.set,yscrollcommand=scroll_y.set) 200 | 201 | scroll_x.pack(side=BOTTOM,fill=X) 202 | scroll_y.pack(side=RIGHT,fill=Y) 203 | scroll_x.config(command=self.attendanceReport.xview) 204 | scroll_y.config(command=self.attendanceReport.yview) 205 | 206 | self.attendanceReport.heading("ID",text="ID") 207 | self.attendanceReport.heading("Roll_No",text="Roll") 208 | self.attendanceReport.heading("Name",text="Name") 209 | self.attendanceReport.heading("Time",text="Time") 210 | self.attendanceReport.heading("Date",text="Date") 211 | self.attendanceReport.heading("Attend",text="Attend") 212 | self.attendanceReport["show"]="headings" 213 | 214 | 215 | # Set Width of Colums 216 | self.attendanceReport.column("ID",width=30) 217 | self.attendanceReport.column("Roll_No",width=70) 218 | self.attendanceReport.column("Name",width=100) 219 | self.attendanceReport.column("Time",width=75) 220 | self.attendanceReport.column("Date",width=80) 221 | self.attendanceReport.column("Attend",width=120) 222 | 223 | self.attendanceReport.pack(fill=BOTH,expand=1) 224 | self.attendanceReport.bind("",self.get_cursor_right) 225 | self.fetch_data() 226 | # # =================================update for mysql button================ 227 | 228 | # #Update button 229 | del_btn=Button(right_frame,command=self.update_data,text="Update",width=12,font=("verdana",12,"bold"),fg="white",bg="navyblue") 230 | del_btn.grid(row=0,column=1,padx=6,pady=10,sticky=W) 231 | #Update button 232 | del_btn=Button(right_frame,command=self.delete_data,text="Delete",width=12,font=("verdana",12,"bold"),fg="white",bg="navyblue") 233 | del_btn.grid(row=0,column=2,padx=6,pady=10,sticky=W) 234 | # ===============================update function for mysql database================= 235 | def update_data(self): 236 | if self.var_id.get()=="" or self.var_roll.get=="" or self.var_name.get()=="" or self.var_time.get()=="" or self.var_date.get()=="" or self.var_attend.get()=="Status": 237 | messagebox.showerror("Error", "All fields are required", parent=self.root) 238 | else: 239 | try: 240 | Update=messagebox.askyesno("Update","Do you want to update this student details",parent=self.root) 241 | if Update > 0: 242 | conn = mysql.connector.connect(user='root', password='Nadeem@786',host='localhost',database='face_recognizer',port=3306) 243 | mycursor = conn.cursor() 244 | mycursor.execute("update stdattendance set std_id=%s,std_roll_no=%s,std_name=%s,std_time=%s,std_date=%s,std_attendance=%s where std_id=%s",( 245 | self.var_id.get(), 246 | self.var_roll.get(), 247 | self.var_name.get(), 248 | self.var_time.get(), 249 | self.var_date.get(), 250 | self.var_attend.get(), 251 | self.var_id.get() 252 | )) 253 | else: 254 | if not Update: 255 | return 256 | messagebox.showinfo("Success","Data is updated!",parent=self.root) 257 | conn.commit() 258 | self.fetch_data() 259 | conn.close() 260 | except Exception as es: 261 | messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root) 262 | # =============================Delete Attendance form my sql============================ 263 | def delete_data(self): 264 | if self.var_id.get()=="": 265 | messagebox.showerror("Error","Please select a student to delete" ,parent=self.root) 266 | else: 267 | try: 268 | delete=messagebox.askyesno("Delete","Are you sure you want to delete this student?",parent=self.root) 269 | if delete>0: 270 | conn = mysql.connector.connect(user='root', password='2912002',host='localhost',database='face_recognition',port=3306) 271 | mycursor = conn.cursor() 272 | sql="delete from stdattendance where std_id=%s" 273 | val=(self.var_id.get(),) 274 | mycursor.execute(sql,val) 275 | else: 276 | if not delete: 277 | return 278 | 279 | conn.commit() 280 | self.fetch_data() 281 | conn.close() 282 | messagebox.showinfo("Delete","Xóa thành công!",parent=self.root) 283 | except Exception as es: 284 | messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root) 285 | # ===========================fatch data form mysql attendance=========== 286 | 287 | def fetch_data(self): 288 | conn = mysql.connector.connect(user='root', password='Nadeem@786',host='localhost',database='face_recognizer',port=3306) 289 | mycursor = conn.cursor() 290 | 291 | mycursor.execute("select * from stdattendance") 292 | data=mycursor.fetchall() 293 | 294 | if len(data)!= 0: 295 | self.attendanceReport.delete(*self.attendanceReport.get_children()) 296 | for i in data: 297 | self.attendanceReport.insert("",END,values=i) 298 | conn.commit() 299 | conn.close() 300 | 301 | # # #============================Reset Data====================== 302 | def reset_data(self): 303 | self.var_id.set("") 304 | self.var_roll.set("") 305 | self.var_name.set("") 306 | self.var_dep.set("") 307 | self.var_time.set("") 308 | self.var_date.set("") 309 | self.var_attend.set("Status") 310 | 311 | # # # =========================Fetch Data Import data =============== 312 | 313 | def fetchData(self,rows): 314 | global mydata 315 | mydata = rows 316 | self.attendanceReport_left.delete(*self.attendanceReport_left.get_children()) 317 | for i in rows: 318 | self.attendanceReport_left.insert("",END,values=i) 319 | print(i) 320 | 321 | 322 | def importCsv(self): 323 | mydata.clear() 324 | fln=filedialog.askopenfilename(initialdir=os.getcwd(),title="Open CSV",filetypes=(("CSV File","*.csv"),("All File","*.*")),parent=self.root) 325 | with open(fln) as myfile: 326 | csvread=csv.reader(myfile,delimiter=",") 327 | for i in csvread: 328 | mydata.append(i) 329 | self.fetchData(mydata) 330 | 331 | 332 | # # #==================Experot CSV============= 333 | def exportCsv(self): 334 | try: 335 | if len(mydata)<1: 336 | messagebox.showerror("Error","No Data Found!",parent=self.root) 337 | return False 338 | fln=filedialog.asksaveasfilename(initialdir=os.getcwd(),title="Open CSV",filetypes=(("CSV File","*.csv"),("All File","*.*")),parent=self.root) 339 | with open(fln,mode="w",newline="") as myfile: 340 | exp_write=csv.writer(myfile,delimiter=",") 341 | for i in mydata: 342 | exp_write.writerow(i) 343 | messagebox.showinfo("Successfuly","Your data is exported!") 344 | except Exception as es: 345 | messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root) 346 | 347 | # # #=============Cursur Function for CSV======================== 348 | 349 | def get_cursor_left(self,event=""): 350 | cursor_focus = self.attendanceReport_left.focus() 351 | content = self.attendanceReport_left.item(cursor_focus) 352 | data = content["values"] 353 | 354 | self.var_id.set(data[0]), 355 | self.var_roll.set(data[1]), 356 | self.var_name.set(data[2]), 357 | self.var_time.set(data[3]), 358 | self.var_date.set(data[4]), 359 | self.var_attendance.set(data[5]) 360 | self.var_dep.set(data[6]), 361 | 362 | # #=============Cursur Function for mysql======================== 363 | 364 | def get_cursor_right(self,event=""): 365 | cursor_focus = self.attendanceReport.focus() 366 | content = self.attendanceReport.item(cursor_focus) 367 | data = content["values"] 368 | 369 | self.var_id.set(data[0]), 370 | self.var_roll.set(data[1]), 371 | self.var_name.set(data[2]), 372 | self.var_time.set(data[3]), 373 | self.var_date.set(data[4]), 374 | self.var_attend.set(data[5]) 375 | # #=========================================Update CSV============================ 376 | 377 | # # export upadte 378 | def action(self): 379 | if self.var_id.get()=="" or self.var_roll.get=="" or self.var_name.get()=="" or self.var_time.get()=="" or self.var_date.get()=="" or self.var_attend.get()=="Status": 380 | messagebox.showerror("Error","Please fill in all required fields!",parent=self.root) 381 | else: 382 | try: 383 | conn = mysql.connector.connect(user='root', password='Nadeem@786',host='localhost',database='face_recognizer',port=3306) 384 | mycursor = conn.cursor() 385 | mycursor.execute("insert into stdattendance values(%s,%s,%s,%s,%s,%s)",( 386 | self.var_id.get(), 387 | self.var_roll.get(), 388 | self.var_name.get(), 389 | self.var_time.get(), 390 | self.var_date.get(), 391 | self.var_attend.get() 392 | )) 393 | 394 | conn.commit() 395 | self.fetch_data() 396 | conn.close() 397 | messagebox.showinfo("Success","All records are saved in the database!",parent=self.root) 398 | except Exception as es: 399 | messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root) 400 | 401 | 402 | conn = mysql.connector.connect(user='root', password='Nadeem@786',host='localhost',database='face_recognizer',port=3306) 403 | mycursor = conn.cursor() 404 | if messagebox.askyesno("Confirmation","Are you sure you want to save attendance on database?"): 405 | for i in mydata: 406 | uid = i[0] 407 | uroll = i[1] 408 | uname = i[2] 409 | utime = i[3] 410 | udate = i[4] 411 | uattend = i[5] 412 | qury = "INSERT INTO stdattendance(std_id, std_roll_no, std_name, std_time, std_date, std_attendance) VALUES(%s,%s,%s,%s,%s,%s)" 413 | mycursor.execute(qury,(uid,uroll,uname,utime,udate,uattend)) 414 | conn.commit() 415 | conn.close() 416 | messagebox.showinfo("Success","Successfully Updated!",parent=self.root) 417 | else: 418 | return False 419 | 420 | if __name__ == "__main__": 421 | root=Tk() 422 | obj=Attendance(root) 423 | root.mainloop() -------------------------------------------------------------------------------- /student.py: -------------------------------------------------------------------------------- 1 | from tkinter import* 2 | from tkinter import ttk 3 | from PIL import Image, ImageTk 4 | from tkinter import messagebox 5 | import mysql.connector 6 | import cv2 7 | import numpy as np 8 | import tkinter 9 | from tkinter import StringVar 10 | import tkinter as tk 11 | 12 | class Student: 13 | def __init__(self,root): 14 | self.var_search = tkinter.StringVar() 15 | self.var_searchTX = tkinter.StringVar() 16 | self.root=root 17 | self.root.geometry("1530x790+0+0") 18 | self.root.title("face Recognition System") 19 | 20 | ########## Variable ############### 21 | 22 | self.var_dep=StringVar() 23 | self.var_course=StringVar() 24 | self.var_year=StringVar() 25 | self.var_semester=StringVar() 26 | self.var_std_id=StringVar() 27 | self.var_std_name=StringVar() 28 | self.var_div=StringVar() 29 | self.var_roll=StringVar() 30 | self.var_gender=StringVar() 31 | self.var_dob=StringVar() 32 | self.var_email=StringVar() 33 | self.var_phone=StringVar() 34 | self.var_address=StringVar() 35 | self.var_teacher=StringVar() 36 | # self.var_radio1=StringVar() 37 | 38 | #FIRST IMAGE 39 | 40 | img=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\atts.jpg") 41 | img=img.resize((500,130),Image.ADAPTIVE) 42 | self.photoimg=ImageTk.PhotoImage(img) 43 | 44 | f_lbl =Label(self.root,image=self.photoimg) 45 | f_lbl.place(x=0,y=0, width=500, height=130) 46 | #SECOND IMAGE 47 | 48 | img1=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\ff.jpg") 49 | img1=img1.resize((500,130),Image.ADAPTIVE) 50 | self.photoimg1=ImageTk.PhotoImage(img1) 51 | 52 | f_lbl =Label(self.root,image=self.photoimg1) 53 | f_lbl.place(x=500,y=0, width=500, height=130) 54 | #THIRD IMAGE 55 | 56 | img2=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\hii.jpg") 57 | img2=img2.resize((500,130),Image.ADAPTIVE) 58 | self.photoimg2=ImageTk.PhotoImage(img2) 59 | 60 | f_lbl =Label(self.root,image=self.photoimg2) 61 | f_lbl.place(x=1000,y=0, width=550, height=130) 62 | 63 | #Baground IMAGE 64 | 65 | img3=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\bgs.jpg") 66 | img3=img3.resize((1530,710),Image.ADAPTIVE) 67 | self.photoimg3=ImageTk.PhotoImage(img3) 68 | 69 | bg_img=Label(self.root,image=self.photoimg3) 70 | bg_img.place(x=0,y=130, width=1530, height=710) 71 | 72 | title_lbl=Label(bg_img,text="STUDENTS MANAGEMENT SYSTEM",font=("times new roman",35,"bold"),bg="white", fg="darkgreen") 73 | title_lbl.place(x=0,y=0,width=1530, height=45) 74 | 75 | 76 | main_frame=Frame(bg_img,bd=2, bg="white") 77 | main_frame.place(x=20, y=50, width=1480, height=600) 78 | 79 | #left label frame 80 | 81 | Left_frame=LabelFrame(main_frame, bd=2,bg="white", relief=RIDGE, text="Student Details", font=("times new roman",12, "bold")) 82 | Left_frame.place(x=10, y=10, width=730, height= 580) 83 | 84 | 85 | img_left=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\stude.jpeg") 86 | img_left=img_left.resize((720,130),Image.ADAPTIVE) 87 | self.photoimg_left=ImageTk.PhotoImage(img_left) 88 | 89 | f_lbl =Label(Left_frame,image=self.photoimg_left) 90 | f_lbl.place(x=5,y=0, width=720, height=130) 91 | 92 | #current course information 93 | current_course_frame=LabelFrame(Left_frame, bd=2,bg="white", relief=RIDGE,text="Current course information",font=("times new roman",12, "bold")) 94 | current_course_frame.place(x=5, y=135, width=720, height= 115) 95 | 96 | # Department 97 | dep_label=Label(current_course_frame, text="Department", font=("times new roman",13,"bold"),bg="white") 98 | dep_label.grid(row=0,column=0,padx=10, sticky=W) 99 | 100 | dep_combo=ttk.Combobox(current_course_frame,textvariable=self.var_dep,font=("times new roman",13,"bold"),state="read only",width=20) 101 | dep_combo["values"]=("Select Department","Computer","IT","Civil","Mechnical") 102 | dep_combo.current(0) 103 | dep_combo.grid(row=0, column=1,padx=2,pady=10,sticky=W) 104 | 105 | #course 106 | course_label=Label(current_course_frame,text="Course",font=("times now roman",13,"bold"),bg="white") 107 | course_label.grid(row=0,column=2,padx=10,sticky=W) 108 | 109 | course_combo=ttk.Combobox(current_course_frame,textvariable=self.var_course,font=("times new roman",13,"bold"),state="readonly",width=20) 110 | course_combo["values"]=("Select Course","FE", "SE","TE","BE") 111 | course_combo.current(0) 112 | course_combo.grid(row=0, column=3,padx=2,pady=10,sticky=W) 113 | 114 | #year 115 | year_label=Label(current_course_frame,text="Year",font=("times new roman",13,"bold"),bg="white") 116 | year_label.grid(row=1,column=0,padx=10,sticky=W) 117 | 118 | year_combo=ttk.Combobox(current_course_frame, textvariable=self.var_year,font=("times new roman",13,"bold"),state="readonly",width=20) 119 | year_combo["values"]=("Select Year","2020-2021","2021-2022","2022-2023","2023-2024","2024-2025") 120 | year_combo.current(0) 121 | year_combo.grid(row=1, column=1,padx=2,pady=10,sticky=W) 122 | 123 | # Semester 124 | semester_label=Label(current_course_frame,text="Semester",font=("times new roman",13,"bold"),bg="white") 125 | semester_label.grid(row=1,column=2,padx=10,sticky=W) 126 | 127 | semester_combo=ttk.Combobox(current_course_frame,textvariable=self.var_semester,font=("times new roman",13,"bold"),state="readonly",width=20) 128 | semester_combo["values"]=("Select Semester","Semester-1","Semester-2") 129 | semester_combo.current(0) 130 | semester_combo.grid(row=1,column=3,padx=2,pady=10,sticky=W) 131 | 132 | #Class Student information 133 | class_student_frame=LabelFrame(Left_frame,bd=2,bg="white",relief=RIDGE,text="Class Students Information",font=("times new roman",12,"bold")) 134 | class_student_frame.place(x=5,y=250,width=720,height=300) 135 | 136 | #student id 137 | #studentId_label=Label(class_student_frame, textvariable=self.var_std_id, text="Student ID:",font=("times new roman", 13, "bold"), bg="white") 138 | studentId_label=Label(class_student_frame,text="Student ID:",font=("times new roman",13,"bold"),bg="white") 139 | studentId_label.grid(row=0,column=0,padx=10,pady=5,sticky=W) 140 | 141 | studentID_entry=ttk.Entry(class_student_frame,textvariable=self.var_std_id,width=20,font=("times new roman",13,"bold")) 142 | studentID_entry.grid(row=0,column=1,padx=10,pady=5,sticky=W) 143 | 144 | #student name 145 | studentName_label=Label(class_student_frame,text="Student Name:",font=("times new roman",13,"bold"),bg="white") 146 | studentName_label.grid(row=0,column=2,pady=5,padx=10,sticky=W) 147 | 148 | studentName_entry=ttk.Entry(class_student_frame,textvariable=self.var_std_name,width=20,font=("times new roman",13,"bold")) 149 | studentName_entry.grid(row=0,column=3,padx=10,pady=5,sticky=W) 150 | 151 | #Class division 152 | class_div_label=Label(class_student_frame,text="Section:",font=("times new roman",13,"bold"),bg="white") 153 | class_div_label.grid(row=1,column=0,pady=5,padx=10,sticky=W) 154 | 155 | # class_div_entry=ttk.Entry(class_student_frame, textvariable=self.var_div, width=20, font=("times new roman", 13, "bold")) 156 | # class_div_entry.grid(row=1, column=1, padx=10,pady=5, sticky=W) 157 | 158 | div_combo=ttk.Combobox(class_student_frame,textvariable=self.var_div, font=("times new roman", 13, "bold"),state="readonly",width=18) 159 | div_combo["values"]=("A", "B", "C", "D", "E","F","G","H","I") 160 | div_combo.current(0) 161 | div_combo.grid(row=1, column=1,padx=10,pady=5,sticky=W) 162 | 163 | #Roll No 164 | roll_no_label=Label(class_student_frame,text="Roll No:",font=("times new roman",13,"bold"),bg="white") 165 | roll_no_label.grid(row=1,column=2,pady=5,padx=10,sticky=W) 166 | 167 | roll_no_entry=ttk.Entry(class_student_frame,textvariable=self.var_roll,width=20,font=("times new roman",13,"bold")) 168 | roll_no_entry.grid(row=1,column=3,padx=10,pady=5,sticky=W) 169 | 170 | #Gender 171 | gender_label=Label(class_student_frame,text="Gender:",font=("times new roman",13,"bold"),bg="white") 172 | gender_label.grid(row=2,column=0,pady=5,padx=10,sticky=W) 173 | 174 | # gender_entry=ttk.Entry(class_student_frame, textvariable=self.var_gender, width=20, font=("times new roman", 13, "bold")) 175 | # gender_entry.grid(row=2, column=1, padx=10,pady=5, sticky=W) 176 | 177 | gender_combo=ttk.Combobox(class_student_frame,textvariable=self.var_gender,font=("times new roman",13,"bold"),state="readonly",width=18) 178 | gender_combo["values"]=("Male","Femail","Other") 179 | gender_combo.current(0) 180 | gender_combo.grid(row=2, column=1,padx=10,pady=5,sticky=W) 181 | 182 | #DOB 183 | dob_label=Label(class_student_frame,text="DOB:",font=("times new roman",13,"bold"),bg="white") 184 | dob_label.grid(row=2,column=2,pady=5,padx=10,sticky=W) 185 | 186 | dob_entry=ttk.Entry(class_student_frame,textvariable=self.var_dob,width=20,font=("times new roman",13,"bold")) 187 | dob_entry.grid(row=2,column=3,padx=10,pady=5,sticky=W) 188 | 189 | #Email 190 | email_label=Label(class_student_frame,text="Email:",font=("times new roman",13,"bold"),bg="white") 191 | email_label.grid(row=3,column=0,pady=5,padx=10,sticky=W) 192 | 193 | email_entry=ttk.Entry(class_student_frame,textvariable=self.var_email,width=20,font=("times new roman",13,"bold")) 194 | email_entry.grid(row=3,column=1,padx=10,pady=5,sticky=W) 195 | 196 | #Phone No 197 | phone_label=Label(class_student_frame,text="Phone No:",font=("times new roman",13,"bold"),bg="white") 198 | phone_label.grid(row=3,column=2,pady=5,padx=10,sticky=W) 199 | 200 | phone_entry=ttk.Entry(class_student_frame,textvariable=self.var_phone,width=20,font=("times new roman",13,"bold")) 201 | phone_entry.grid(row=3,column=3,padx=10,pady=5,sticky=W) 202 | 203 | #Address 204 | address_label=Label(class_student_frame,text="Address:",font=("times new roman",13,"bold"),bg="white") 205 | address_label.grid(row=4,column=0,pady=5,padx=10,sticky=W) 206 | 207 | address_entry=ttk.Entry(class_student_frame, textvariable=self.var_address, width=20,font=("times new roman",13,"bold")) 208 | address_entry.grid(row=4,column=1,padx=10,pady=5,sticky=W) 209 | 210 | #Teacher name 211 | teacher_label=Label(class_student_frame,text="Teacher Name:",font=("times new roman",13,"bold"),bg="white") 212 | teacher_label.grid(row=4,column=2,pady=5,padx=10,sticky=W) 213 | 214 | teacher_entry=ttk.Entry(class_student_frame,textvariable=self.var_teacher,width=20,font=("times new roman",13,"bold")) 215 | teacher_entry.grid(row=4,column=3,padx=10,pady=5,sticky=W) 216 | 217 | # radio Button 218 | self.var_radio1=StringVar() 219 | radionbtn1=ttk.Radiobutton(class_student_frame, variable=self.var_radio1,text="Take Photo Sample",value="Yes") 220 | radionbtn1.grid(row=6,column=0) 221 | 222 | # self.var_radio2=StringVar() 223 | radionbtn2=ttk.Radiobutton(class_student_frame,variable=self.var_radio1,text="No Photo Sample",value="No") 224 | radionbtn2.grid(row=6,column=1) 225 | 226 | #botton frame 227 | btn_frame=Frame(class_student_frame,bd=2,relief=RIDGE,bg="white") 228 | btn_frame.place(x=0,y=200,width=715,height=35) 229 | 230 | save_btn=Button(btn_frame,text="save",command=self.add_data,width=17,font=("times new roman",13,"bold"),bg="blue",fg="white") 231 | save_btn.grid(row=0,column=0) 232 | 233 | update_btn=Button(btn_frame,text="Update",command=self.update_data,width=17,font=("times new roman",13,"bold"),bg="blue",fg="white") 234 | update_btn.grid(row=0,column=1) 235 | 236 | delete_btn=Button(btn_frame,text="Delete",command=self.delete_data, width=17,font=("times new roman",13,"bold"),bg="blue",fg="white") 237 | delete_btn.grid(row=0,column=2) 238 | 239 | reset_btn=Button(btn_frame,text="Reset",command=self.reset_data, width=17,font=("times new roman",13,"bold"),bg="blue",fg="white") 240 | reset_btn.grid(row=0, column=3) 241 | 242 | btn_frame1=Frame(class_student_frame,bd=2, relief=RIDGE,bg="white") 243 | btn_frame1.place(x=0,y=235,width=715,height=35) 244 | 245 | take_photo_btn=Button(btn_frame1,command=self.generate_dataset,text="Take Photo Sample",width=34, font=("times new roman", 13,"bold"), bg="blue", fg="white") 246 | take_photo_btn.grid(row=0, column=0) 247 | 248 | update_photo_btn=Button(btn_frame1, text="Update Photo Sample",command=self.generate_dataset, width=34, font=("times new roman", 13,"bold"), bg="blue", fg="white") 249 | update_photo_btn.grid(row=0, column=1 ) 250 | 251 | 252 | #Right label frame 253 | 254 | Right_frame=LabelFrame(main_frame, bd=2,bg="white", relief=RIDGE, text="Student Details", font=("times new roman",12, "bold")) 255 | Right_frame.place(x=750, y=10, width=720, height= 580) 256 | 257 | 258 | img_right=Image.open(r"C:\Users\caree\Desktop\Face Reco\image\love.jpg") 259 | img_right=img_right.resize((720,130),Image.ADAPTIVE) 260 | self.photoimg_right=ImageTk.PhotoImage(img_right) 261 | 262 | f_lbl =Label(Right_frame,image=self.photoimg_right) 263 | f_lbl.place(x=5,y=0, width=720, height=130) 264 | 265 | 266 | ############################################# Searching System ####################################### 267 | 268 | Search_frame=LabelFrame(Right_frame, bd=2,bg="white", relief=RIDGE, text="Search System", font=("times new roman",12, "bold")) 269 | Search_frame.place(x=5, y=135, width=710, height=70) 270 | 271 | search_label=Label(Search_frame, text="Search By:", font=("times new roman", 13, "bold"), bg="red", fg="white") 272 | search_label.grid(row=0, column=0, pady=5, padx=10, sticky=W) 273 | 274 | search_combo=ttk.Combobox(Search_frame,font=("times new roman", 13,"bold"), state="readonly",width=15) 275 | search_combo["values"]=("Select", "Roll-No", "Phone-No") 276 | search_combo.current(0) 277 | search_combo.grid(row=0, column=1,padx=2,pady=10,sticky=W) 278 | 279 | # self.var_search=StringVar() 280 | search_entry=ttk.Entry(Search_frame,textvariable=self.var_search, width=15, font=("times new roman", 13, "bold")) 281 | search_entry.grid(row=0, column=2, padx=10,pady=5, sticky=W) 282 | 283 | 284 | search_btn=Button(Search_frame, text="Search",command=self.search_data, width=12, font=("times new roman", 12, "bold"), bg="blue", fg="white") 285 | search_btn.grid(row=0, column=3, padx=4) 286 | 287 | showALL_btn=Button(Search_frame, text="Show All",command=self.fetch_data, width=12, font=("times new roman", 12, "bold"), bg="blue", fg="white") 288 | showALL_btn.grid(row=0, column=4, padx=4) 289 | 290 | ##################### Table frame ################# scroll bar 291 | table_frame=Frame(Right_frame, bd=2,bg="white", relief=RIDGE) 292 | table_frame.place(x=5, y=210, width=710, height=250) 293 | 294 | scroll_x=ttk.Scrollbar(table_frame, orient=HORIZONTAL) 295 | scroll_y=ttk.Scrollbar(table_frame, orient=VERTICAL) 296 | 297 | self.student_table=ttk.Treeview(table_frame, column=("dep", "course","year", "sem", "id", "name","div","roll","gender","dob","email", "phone" ,"address","teacher","photo"),xscrollcommand=scroll_x.set, yscrollcommand=scroll_y.set) 298 | scroll_x.pack(side=BOTTOM, fill=X) 299 | scroll_y.pack(side=RIGHT, fill=Y) 300 | 301 | scroll_x.config(command=self.student_table.xview) 302 | scroll_y.config(command=self.student_table.yview) 303 | 304 | 305 | self.student_table.heading("dep",text="Department") 306 | self.student_table.heading("course",text="Course") 307 | self.student_table.heading("year",text="Year") 308 | self.student_table.heading("sem",text="Semester") 309 | self.student_table.heading("id",text="Student_Id") 310 | self.student_table.heading("name",text="Name") 311 | self.student_table.heading("div",text="Division") 312 | self.student_table.heading("roll",text="Roll") 313 | self.student_table.heading("gender",text="Gender") 314 | self.student_table.heading("dob",text="DOB") 315 | self.student_table.heading("email",text="Email") 316 | self.student_table.heading("phone",text= "Phone") 317 | self.student_table.heading("address",text="Address") 318 | self.student_table.heading("teacher",text="Teacher") 319 | self.student_table.heading("photo",text="PhotoSampleStatus") 320 | self.student_table["show"]="headings" 321 | 322 | self.student_table.column("dep",width=100) 323 | self.student_table.column("course",width=100) 324 | self.student_table.column("year",width=100) 325 | self.student_table.column("sem",width=100) 326 | self.student_table.column("id",width=100) 327 | self.student_table.column("name",width=100) 328 | self.student_table.column("div",width=100) 329 | self.student_table.column("roll",width=100) 330 | self.student_table.column("gender",width=100) 331 | self.student_table.column("dob",width=100) 332 | self.student_table.column("email",width=100) 333 | self.student_table.column("phone",width=100) 334 | self.student_table.column("address",width=100) 335 | self.student_table.column("teacher",width=100) 336 | self.student_table.column("photo",width=150) 337 | 338 | 339 | self.student_table.pack(fill=BOTH,expand=1) 340 | self.student_table.bind("",self.get_coursor) 341 | self.fetch_data() 342 | 343 | 344 | ########### Function Declation ######################## 345 | 346 | def add_data(self): 347 | if self.var_dep.get()=="Select Department" or self.var_std_name.get()=="" or self.var_std_id.get()=="": 348 | messagebox.showerror("Error","All Fields are required",parent=self.root) 349 | else: 350 | # messagebox.showinfo("success","welcomebro") 351 | try: 352 | conn=mysql.connector.connect(host="localhost",username="root",password="Nadeem@786",database="face_recognizer") 353 | my_cursor=conn.cursor() 354 | my_cursor.execute("insert into student values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",( 355 | 356 | self.var_dep.get(), 357 | self.var_course.get(), 358 | self.var_year.get(), 359 | self.var_semester.get(), 360 | self.var_std_id.get(), 361 | self.var_std_name.get(), 362 | self.var_div.get(), 363 | self.var_roll.get(), 364 | self.var_gender.get(), 365 | self.var_dob.get(), 366 | self.var_email.get(), 367 | self.var_phone.get(), 368 | self.var_address.get(), 369 | self.var_teacher.get(), 370 | self.var_radio1.get() 371 | 372 | )) 373 | conn.commit() 374 | self.fetch_data() 375 | conn.close() 376 | messagebox.showinfo("Success","Student details has been added Successfully",parent=self.root) 377 | except Exception as es: 378 | messagebox.showerror("Error",f"Due To :{str(es)}",parent=self.root) 379 | 380 | #################### Fetch data ################ 381 | 382 | def fetch_data(self): 383 | conn=mysql.connector.connect(host="localhost",username="root",password="Nadeem@786",database="face_recognizer") 384 | my_cursor=conn.cursor() 385 | 386 | my_cursor.execute("select * from student") 387 | data=my_cursor.fetchall() 388 | 389 | if len(data)!=0: 390 | self.student_table.delete(*self.student_table.get_children()) 391 | for i in data: 392 | self.student_table.insert("",END,values=i) 393 | conn.commit() 394 | conn.close() 395 | 396 | ################## get cursor data ##################### 397 | 398 | def get_coursor(self, event=""): 399 | cursor_focus=self.student_table.focus() 400 | content=self.student_table.item(cursor_focus) 401 | data=content["values"] 402 | 403 | self.var_dep.set(data[0]), 404 | self.var_course.set(data[1]), 405 | self.var_year.set(data[2]), 406 | self.var_semester.set(data[3]), 407 | self.var_std_id.set(data[4]), 408 | self.var_std_name.set(data[5]), 409 | self.var_div.set(data[6]), 410 | self.var_roll.set(data[7]), 411 | self.var_gender.set(data[8]), 412 | self.var_dob.set(data[9]), 413 | self.var_email.set(data[10]), 414 | self.var_phone.set(data[11]), 415 | self.var_address.set(data[12]), 416 | self.var_teacher.set(data[13]), 417 | self.var_radio1.set(data[14]) 418 | 419 | 420 | ########### Update Function ############### 421 | 422 | def update_data(self): 423 | if self.var_dep.get() == "Select Department" or self.var_std_name.get() == "" or self.var_std_id.get() == "": 424 | messagebox.showerror("Error", "All fields are required", parent=self.root) 425 | else: 426 | try: 427 | update = messagebox.askyesno("Update", "Do you want to update this student details", parent=self.root) 428 | if update: 429 | conn = mysql.connector.connect(host="localhost", username="root", password="Nadeem@786", database="face_recognizer") 430 | my_cursor = conn.cursor() 431 | my_cursor.execute( 432 | """UPDATE student SET Name=%s, Dep=%s, Course=%s, Year=%s, Semester=%s, Division=%s, Roll=%s, Gender=%s, 433 | Dob=%s, Email=%s, Phone=%s, Address=%s, Teacher=%s, PhotoSample=%s WHERE Student_id=%s""", 434 | ( 435 | self.var_std_name.get(), 436 | self.var_dep.get(), 437 | self.var_course.get(), 438 | self.var_year.get(), 439 | self.var_semester.get(), 440 | self.var_div.get(), 441 | self.var_roll.get(), 442 | self.var_gender.get(), 443 | self.var_dob.get(), 444 | self.var_email.get(), 445 | self.var_phone.get(), 446 | self.var_address.get(), 447 | self.var_teacher.get(), 448 | self.var_radio1.get(), 449 | self.var_std_id.get() 450 | ) 451 | ) 452 | conn.commit() 453 | self.fetch_data() 454 | conn.close() 455 | messagebox.showinfo("Success", "Student details successfully updated", parent=self.root) 456 | else: 457 | if not update: 458 | return 459 | except Exception as es: 460 | messagebox.showerror("Error", f"Due To: {str(es)}", parent=self.root) 461 | 462 | def delete_data(self): 463 | if self.var_std_id.get()=="": 464 | messagebox.showerror("Error","Please select a student to delete" ,parent=self.root) 465 | else: 466 | try: 467 | delete=messagebox.askyesno("Delete","Are you sure you want to delete this student?",parent=self.root) 468 | if delete>0: 469 | conn = mysql.connector.connect(host="localhost", username="root", password="Nadeem@786", database="face_recognizer") 470 | mycursor = conn.cursor() 471 | sql="delete from student where Student_id=%s" 472 | val=(self.var_std_id.get(),) 473 | mycursor.execute(sql,val) 474 | else: 475 | if not delete: 476 | return 477 | 478 | conn.commit() 479 | self.fetch_data() 480 | conn.close() 481 | messagebox.showinfo("Delete","Student details successfully deleted",parent=self.root) 482 | except Exception as es: 483 | messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root) 484 | 485 | ######### Reset Data ######### 486 | 487 | def reset_data(self): 488 | self.var_dep.set("Status"), 489 | self.var_std_name.set(""), 490 | self.var_course.set("Status"), 491 | self.var_year.set("Select Year") 492 | self.var_semester.set("Status"), 493 | self.var_std_id.set(""), 494 | self.var_std_name.set(""), 495 | self.var_div.set("Status"), 496 | self.var_roll.set(""), 497 | self.var_gender.set("Status"), 498 | self.var_dob.set(""), 499 | self.var_email.set(""), 500 | self.var_phone.set(""), 501 | self.var_address.set(""), 502 | self.var_teacher.set(""), 503 | self.var_radio1.set("") 504 | 505 | #*********************************************************************************************************************** 506 | ########## Search Dat a################# 507 | 508 | def search_data(self): 509 | if self.var_search.get() == "" or self.var_searchTX.get() == "Select": 510 | messagebox.showerror("Error", "Select Combo option and enter entry box", parent=self.root) 511 | else: 512 | try: 513 | conn = mysql.connector.connect(user='root', password='Nadeem@786', host='localhost', 514 | database="face_recognizer", port=3306) 515 | my_cursor = conn.cursor() 516 | 517 | # First query 518 | sql = "SELECT Dep, course, year, semester, Student_id, Name, Division,Roll, Gender, Dob,Email, Phone, Address,Teacher, PhotoSample FROM student WHERE Roll = %s" 519 | my_cursor.execute(sql, (self.var_search.get(),)) 520 | rows = my_cursor.fetchall() 521 | 522 | # Checking if rows exist 523 | if len(rows) != 0: 524 | self.student_table.delete(*self.student_table.get_children()) 525 | for i in rows: 526 | self.student_table.insert("", END, values=i) 527 | else: 528 | messagebox.showerror("Error", "Data Not Found", parent=self.root) 529 | 530 | conn.commit() 531 | conn.close() 532 | 533 | except mysql.connector.Error as err: 534 | messagebox.showerror("Error", f"Database Error: {err}", parent=self.root) 535 | except Exception as e: 536 | messagebox.showerror("Error", f"An unexpected error occurred: {e}", parent=self.root) 537 | 538 | #################Generating Data############# 539 | 540 | def generate_dataset(self): 541 | 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_phone.get()=="" or self.var_address.get()=="" or self.var_teacher.get()=="": 542 | messagebox.showerror("Error", "All fields are required", parent=self.root) 543 | else: 544 | try: 545 | 546 | conn = mysql.connector.connect(user='root', password='Nadeem@786',host='localhost',database='face_recognizer',port=3306) 547 | mycursor = conn.cursor() 548 | mycursor.execute("select * from student") 549 | myreslut = mycursor.fetchall() 550 | id=0 551 | for x in myreslut: 552 | id+=1 553 | 554 | mycursor.execute("update student set Dep=%s, Course=%s, Year=%s, Semester=%s, Name=%s, Division=%s, Roll=%s, Gender=%s,Dob=%s, Email=%s, Phone=%s, Address=%s, Teacher=%s,PhotoSample=%s WHERE Student_id=%s",( 555 | self.var_dep.get(), 556 | self.var_course.get(), 557 | self.var_year.get(), 558 | self.var_semester.get(), 559 | self.var_std_name.get(), 560 | self.var_div.get(), 561 | self.var_roll.get(), 562 | self.var_gender.get(), 563 | self.var_dob.get(), 564 | self.var_email.get(), 565 | self.var_phone.get(), 566 | self.var_address.get(), 567 | self.var_teacher.get(), 568 | self.var_radio1.get(), 569 | self.var_std_id.get()==id+1 570 | )) 571 | conn.commit() 572 | self.fetch_data() 573 | self.reset_data() 574 | conn.close() 575 | 576 | # ====================part of opencv======================= 577 | 578 | face_classifier = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") 579 | 580 | def face_croped(img): 581 | # conver gary sacle 582 | gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) 583 | faces = face_classifier.detectMultiScale(gray,1.3,5) 584 | #Scaling factor 1.3 585 | # Minimum naber 5 586 | for (x,y,w,h) in faces: 587 | face_croped=img[y:y+h,x:x+w] 588 | return face_croped 589 | cap=cv2.VideoCapture(0) 590 | img_id=0 591 | while True: 592 | ret,my_frame=cap.read() 593 | if face_croped(my_frame) is not None: 594 | img_id+=1 595 | 596 | face=cv2.resize(face_croped(my_frame),(200,200)) 597 | face=cv2.cvtColor(face,cv2.COLOR_BGR2GRAY) 598 | file_path="data/user."+str(id)+"."+str(img_id)+".jpg" 599 | cv2.imwrite(file_path,face) 600 | cv2.putText(face,str(img_id),(50,50),cv2.FONT_HERSHEY_COMPLEX,2,(0,255,0),2) 601 | cv2.imshow("Capture Images",face) 602 | 603 | if cv2.waitKey(1)==13 or int(img_id)==100: 604 | break 605 | cap.release() 606 | cv2.destroyAllWindows() 607 | messagebox.showinfo("Result","Generating data sets completed!",parent=self.root) 608 | except Exception as es: 609 | messagebox.showerror("Error",f"Due to: {str(es)}",parent=self.root) 610 | 611 | 612 | 613 | 614 | #************************************************************************************************************************** 615 | 616 | if __name__ == "__main__": 617 | 618 | root=Tk() 619 | obj = Student(root) 620 | root.mainloop() 621 | --------------------------------------------------------------------------------