Face - Detection - System - Report Final Part-1
Face - Detection - System - Report Final Part-1
SYSTEM
Submitted by:
ZUHAIB ALAM– Reg#: 2020-0620-1
ZIA ULLAH– Reg#: 2020-0602-1
Session: 2020-2024
Submitted by:
ZUHAIB ALAM– Reg#: 2020-0620-1
ZIA ULLAH– Reg#: 2020-0602-1
Session: 2020-2024
Supervised by
Mr. ABDUL MUNIM KHAN
Lecturer of Computer Science
DEPARTMENT OF COMPUTER SCIENCE
GOVT DEGREE COLLEGE CHITRAL LOWER
i
CERTIFICATE
This is to certify that all the suggested changes and modification proposed by the external examiner
have been incorporated in the final copy of this thesis and there exists no further
discrepancy in this regard.
SUPERVISORY COMMITTEE:
ii
DEDICATION
This project is an ardent dedication to our beloved parents, whose incessant hard work, Prayers,
sacrifice, and financial assistance paved a way for the accomplishment. We are greatly indebted to
our respected supervisor, Mr. ABDUL MUNIM KHAN, due to whose direction and constant support
we had been enabled to complete this project; we have developed and could reach success through his
able guidance.
A special appreciation to Mr. NASIR MEHMOOD whose consistency in support and invaluable
Guidance has been a great help through this project. His expertise, along with encouragement, greatly
shaped our path to completeness..
iii
AKNOWLEDGMENT
I would like to thank all those who have been able to help me develop this thesis project, “Face
Recognition Attendance System." It is because of their guidance and encouragement that this research
work became successful.
Thanks also to my supervisor, Sir Abdul Munim Khan, for all the guidance, patience, and support
given during this period. Their insightful comments and recommendations have greatly shaped the
direction of this work.
I am thankful to my favorite sir, Mubarak Amin, for supporting me at all the various stages of my
project.
I would like to extend my gratitude towards my family and friends who were always there to help me
in every manner during this trying moment. Their encouragement was so powerful that it made me
conquer the obstacles that blocked my way and keep in line with my aim.
I am grateful to the developers and contributors whose work made these technologies possible,
namely, OpenCV, deep learning techniques, and the Python libraries that made it easier for me to
develop the face recognition algorithm. Thanks to the open-source community for such powerful
tools.
I thank the faculty members and staff of Government Degree College for cooperation and providing a
good atmosphere for study. At the same time, it would not be wrong to acknowledge the institutional
resources involved in this research work as well.
I am thankful to ChatGPT for supporting me throughout different stages of my project from writing
to improving code, and suggesting modifications of the system design and its implementation.
iv
ABSTRACT
The attendance system for students in institutions through advanced facial recognition technology
would be streamlined in the face recognition attendance system. The system would be free of manual
attendance marking and errors caused by human beings and would provide a secure way of tracking
attendance.
The system is centered on a face recognition algorithm. Based on the OpenCV technique, the system
can analyze the facial features and hence identify and authenticate an individual based on his face
recognition. The system has an integrated set of modules meant to work together, resulting in a
comprehensive attendance management solution.
Sign up Module (sign up.py): This module enables user registration, both for the students and staff.
Once registered, the system records and stores facial images of each individual in the database. This
ensures that individuals are recognized by their faces when marking attendance.
Module (login.py): This login module handles the user validation login process. It makes the process
impossible for unauthorized users because once a user inputs authentic credentials, they are opened
up to the attendance panel.
Main Application (main.py): This is an interface that users interact to get through the different
elements such as attendance, Face recognition, and views all the attendance records. Thus, it
integrates all other functions together in a usable graphical user interface that gets powered by
Tkinter.
Training Module train.py: The training module teaches the facial recognition model on how to
recognize facial pictures. It captures various pictures of faces from the different registered users to
produce robust data that enhances the face recognition model's accuracy.
Face Recognition (FaceRecognize.py): This module contains the implementation of facial recognition
algorithm. It will take in camera feeds from real time and match up with a stored database, and then
marks attendance appropriately.
v
Attendance Management (attendance.py): Attendance module manages and keeps a record of
attendance by student based on facial recognition. It makes reports on both individual student and
classes so that one can efficiently monitor and make reports.
Help Desk (help.py): It is a help desk for the users offering an intuitive interface. Thus, if any
problem comes up, it guides or directs users to contact its contact details and further seek assistance.
Developer Information (developer.py): Information about the development team behind the system
and the team of collaborators who have produced the project. It also contains information on the
objectives of the project and the technologies used.
The Face Recognition Attendance System is an integrated solution for the traditional process of
attendance from the traditional attendance systems, with security and efficiency in the terms of
accuracy with low possibilities of proxy attendance, making it highly efficient in all processes
involved in attending. The benefits of automatic management of attendance include time-saving and
the reduction of administrative work as well as higher transparency and reliability in the attendance
process.
vi
Contents
CERTIFICATE..............................................................................................................................................................ii
DEDICATION...............................................................................................................................................................iii
AKNOWLEDGMENT.................................................................................................................................................iv
ABSTRACT....................................................................................................................................................................v
Chapter 1.........................................................................................................................................................................1
1 INTRODUCTION..................................................................................................................................................1
1.1 Project Definition..............................................................................................................................................1
1.2 Project Objectives.............................................................................................................................................1
1.3 Project Specification.........................................................................................................................................1
1.4 Product Architecture and Components..........................................................................................................2
1.4.1 Functional Diagram......................................................................................................................................2
1.5 Applications.......................................................................................................................................................3
Chapter 2.........................................................................................................................................................................4
2 EXISTING SYSTEM.............................................................................................................................................4
2.1 Project Background..........................................................................................................................................4
2.2 Existing system for Attendance Management................................................................................................4
2.2.1 Manual Attendance Systems........................................................................................................................4
2.2.2 Biometric Attendance Systems....................................................................................................................5
2.2.3 RFID-Based Attendance Systems................................................................................................................5
2.2.4 Web-Based and Mobile Attendance Systems.............................................................................................5
2.3 Limitation of Existing System..........................................................................................................................6
2.4 Proposed system: Attendance System Based on Face Recognition..............................................................6
2.4.1 Introduction to Proposed System................................................................................................................6
2.4.2 Features of the Proposed System................................................................................................................7
2.4.3 Technologies Used.........................................................................................................................................7
2.5 Comparison between Existing and Proposed system.....................................................................................8
2.6 Previous Work on Face Recognition-Based Attendance Systems................................................................8
2.6.1 PROJECT#1..................................................................................................................................................8
2.6.2 PROJECT#2..................................................................................................................................................9
2.6.3 PROJECT#3................................................................................................................................................10
2.7 Comparative Study.........................................................................................................................................11
Chapter 3.......................................................................................................................................................................13
3 REQUIREMENT ANALYSIS AND METHODOLOGY................................................................................13
3.1 Introduction.....................................................................................................................................................13
vii
3.2 Functional Requirements...............................................................................................................................13
3.2.1 User Registration and Authentication......................................................................................................13
3.2.2 Main Dashboard and Navigation..............................................................................................................14
3.2.3 Student Management.................................................................................................................................14
3.2.4 Face Recognition and Attendance Tracking............................................................................................14
3.2.5 Face Recognition Model Training.............................................................................................................15
3.3 Non-Functional Requirements.......................................................................................................................15
3.3.1 Performance Requirements.......................................................................................................................15
3.3.2 Usability Requirements..............................................................................................................................15
3.3.3 Security Requirements...............................................................................................................................16
3.3.4 Reliability and Availability........................................................................................................................16
3.3.5 Maintainability and Extensibility..............................................................................................................16
3.4 Hardware and Software Requirements........................................................................................................16
3.4.1 Software Requirement...............................................................................................................................16
3.4.2 Hardware Requirement.............................................................................................................................16
3.5 Data Flow.........................................................................................................................................................16
3.6 System Architecture........................................................................................................................................17
3.7 Methodology....................................................................................................................................................18
3.7.1 Agile methodology......................................................................................................................................18
3.7.2 Tools and Technologies Used.....................................................................................................................18
3.7.3 Face Recognition Algorithm......................................................................................................................18
3.8 Summary..........................................................................................................................................................19
Chapter 4.......................................................................................................................................................................20
4 SYSTEM DESIGN...............................................................................................................................................20
4.1 Design Constraints..........................................................................................................................................20
4.1.1 Design Constraint: Engineering Standards.............................................................................................20
4.1.2 Design Constraint: Environmental...........................................................................................................20
4.1.3 Design Constraint: Ethical.........................................................................................................................20
4.2 Design Methodology........................................................................................................................................20
4.3 Database Design..............................................................................................................................................21
4.3.1 Overview......................................................................................................................................................21
4.3.2 Tables and their Attributes........................................................................................................................21
4.3.3 Relationship between Tables.....................................................................................................................24
4.4 User interface (UI) Design..............................................................................................................................24
4.4.1 User Registration module (signup.py)......................................................................................................24
4.4.2 User Authentication Module (login.py)....................................................................................................25
4.4.3 Main application module (main.py)..........................................................................................................26
4.4.4 Student Detail module (student.py)..........................................................................................................28
viii
4.4.5 Train photos module (train.py).................................................................................................................29
4.4.6 Face Recognition module (FaceRecognition.py)......................................................................................30
4.4.7 Attendance student module (attendance.py)............................................................................................31
4.4.8 Help module (help.py)................................................................................................................................32
4.4.9 Developer's Contact Information:............................................................................................................34
4.4.10 Developer module (developer.py)..............................................................................................................35
Chapter 5.......................................................................................................................................................................37
5 SYSTEM IMPLEMENTATION........................................................................................................................37
5.1 Introduction.....................................................................................................................................................37
5.2 Overview of the System Modules...................................................................................................................37
5.3 Libraries and algorithms................................................................................................................................38
5.3.1 Tkinter.........................................................................................................................................................38
5.3.2 PIL (Python imaging Library)..................................................................................................................39
5.3.3 OpenCv........................................................................................................................................................41
5.3.4 Training a Face Recognition Model..........................................................................................................44
5.3.5 Saving the Trained Model..........................................................................................................................44
5.3.6 Displaying Processed Image for Training................................................................................................45
5.3.7 Face Recognition using LBPH (Local Binary Patterns Histogram)......................................................45
5.3.8 Face Detection & Recognition in Video Stream......................................................................................45
5.3.9 Attendance Logging....................................................................................................................................46
Chapter 6.......................................................................................................................................................................47
6 SYSTEM TESTING AND ANALYSIS..............................................................................................................47
6.1 Testing Overview.............................................................................................................................................47
6.2 Performance Testing.......................................................................................................................................47
6.2.1 Unit Testing.................................................................................................................................................47
6.2.2 Integration Testing.....................................................................................................................................47
6.2.3 UAT..............................................................................................................................................................47
6.2.4 Performance evaluation Testing................................................................................................................48
6.2.5 Security Testing..........................................................................................................................................48
6.3 Testing Results.................................................................................................................................................48
6.3.1 Face Recognition Accuracy........................................................................................................................48
6.3.2 Attendance Marking...................................................................................................................................48
6.3.3 User Interface..............................................................................................................................................48
6.3.4 System Performance...................................................................................................................................48
6.3.5 Security........................................................................................................................................................48
6.4 Conclusion........................................................................................................................................................49
6.5 System analysis................................................................................................................................................49
6.5.1 Personal Growth Journey..........................................................................................................................49
ix
6.5.2 System Objectives and Scope.....................................................................................................................49
6.5.3 Future Scope and Enhancements..............................................................................................................50
Chapter 7.......................................................................................................................................................................51
7 CONCLUSION AND FUTURE RECOMENDATION....................................................................................51
7.1 Conclusion........................................................................................................................................................51
7.2 Future Recommendations..............................................................................................................................51
8 References.............................................................................................................................................................52
x
Chapter 1
1 INTRODUCTION
When teachers do attendance in the class on his/her own, chances are there for making errors and also
it consumes good period of class lecture. However, this particular system does not possess any
chances of errors and also saves a lot of time.
Image Enhancement: The picture taken by the camera should be clear. The system will also
try to enhance the image to make it easier to extract features and recognize the face, ensuring
there are no mistakes when marking attendance.
Image to Grayscale: In this process, the captured image is converted into grayscale using
2
OpenCv library. This means that a 32-bit or 16-bit image is changed into an 8-bit image so
that our pattern matching algorithm can work accurately.
Face detection: Face detection algorithm Haar Cascade Classifier will detect the face from the
image. As mentioned above, the image will be converted to grayscale, and then the face will
be detected through Haar Cascade Classifier algorithm.
Feature Extraction: After detecting the face in the image, the system will now search for
features within that face. This means the Local Binary Pattern (LBP) algorithm will try to
identify and extract the specific features present in that particular face
Face Database: Once the classifier is trained with the faces and IDs, it is saved to disk for later
use. We use this line of code in train.py for saving the trained model.
Face Recognition: After the entire process is completed, when a student comes for attendance,
their face will be recognized. To recognize the face, we have used a specific algorithm, which
will be discussed in detail in the upcoming chapters. Recognition means that the student's face
will be checked to see if it matches any of the faces stored in the database. This matching is
based on all the features.
Update Attendance Sheet.xlsx: If the student’s image matches the one stored in the database,
the algorithm updates the attendance record with the student’s name. The attendance sheet
(Excel file) is also updated accordingly
1.5 Applications
Large Application in Institute Attendance System:
This is a big application used in institutes to take attendance for different classes. The system
takes attendance quickly and reduces human errors, meaning it lowers the mistakes that
people usually make.
Large Application of Computer Vision:
Computer vision is being used in many fields, such as Communication, Biomedical
(healthcare), and Automatic Product Inspection (checking product quality). In these areas,
computer vision has become very important and useful, as it helps automate many tasks and
improves efficiency.
3
Chapter 2
2 EXISTING SYSTEM
Traditionally, the management of attendance in institutions of learning has been conducted either
manually or through conventional automated systems. Such systems have inherent problems, such as
time-consuming processes, human error, and inefficiency. This chapter reviews the existing systems
that are employed in tracking attendance and indicates some of the inadequacies in current practices.
Thereafter, the Proposed System—the Face Recognition System (FRS)—is presented as a more
efficient, secure, and automated means of conducting attendance.
The main objective of this project is to make the attendance process easier and faster. The traditional
methods of using ID cards or manually calling out attendance and writing it down are very time-
consuming and inefficient. The system will detect faces in the classroom of students and link them
with stored information within the database. With face detection and identification, it can easily
determine if the student is in the class or not.
The most ancient and widely followed attendance management system in any school is the manual
attendance system. This is the process that occurs in this system:
Process: The instructor begins the class by taking the roll call and noting it down either on paper or
electronic spreadsheets.
2.2.1.1 Challenges
Time-Consuming: Preparing a roll call manually is quite time-consuming, especially in large classes.
Human Error: There is a tendency to forget to mark the students either as present or absent while it
creates wrong records.
Forgery Risk: One of the students may try forging signatures or may get one of his peers to mark as
'present'.
4
Data Loss: Paper based record may be lost or may be damaged or may even get destroyed, that results in
historical data loss.
5
2.2.4.1 Challenges
Poor Connectivity: These systems face connectivity issues with the network, especially in areas of poor
internet connectivity.
Authentication Problems: These systems might still rely on student input, like clicking buttons or
scanning QR codes, which can lead to errors or even intentional misuse, like marking a student's
attendance for their friend.
Security Risks: Online or mobile storage of attendance data opens security risks, since an unauthorized
access or data breach may result in the loss of sensitive information about the students.
6
Logging Student Attendance: The system registers and logs the attendance of recognized students
with the exact dates and times of every session.
Database Management: Each data of the students, including photos taken and attendance records
will be stored in a protected database for future access
Training module: the system supports on-cycle training to update the models periodically as new
students or enhancements are added to them.
7
4. MySQL/SQLite: For storing student and attendance data in a structured database.
8
faces, crops and stores them, and then compares them for recognition.
Technology Used
This project uses two main algorithms: Viola-Jones algorithm for face detection and Hidden Markov
Model (HMM) with SVD for face recognition.
1. The Viola-Jones algorithm can be implemented in several software programs, such as MATLAB,
OpenCV, and web browsers (using Adobe Flash).
2. The existing implementation of the Hidden Markov Model with SVD for face recognition is
available in MATLAB, C++, and OpenCV libraries
2.6.2 PROJECT#2
In 2012, students at the University of Nairobi developed this project as part of their final year work. The
system consists of two main modules.
The first module, called the face detector, is a portable device that functions as a camera. This camera
captures students' faces and saves them in a file using computer vision algorithms for face detection and
extraction.
The second module is a desktop application that carries out face recognition on the stored images,
records the students' attendance, and saves the results in a database for future use.
9
The following flowchart illustrates how information flows throughout the entire process.
Technology Used: The tools used to implement this system are divided into two categories: Mobile
Tools and Desktop Tools.
Mobile Tools: The Face Detection Module will use the OpenCV library, which includes the frontal Haar
Cascade face detector. This will be implemented in Android Studio.
OpenCV for Android Library - This is an open-source library that provides programming
functions for real-time computer vision.
Android Studio/Eclipse IDE - Android Studio is the official IDE for Android application
development, based on IntelliJ IDEA.
Desktop Tools
EmguCV Library - EmguCV is a cross-platform .NET wrapper for the OpenCV image processing
library. OpenCV/EmguCV uses a Haar Cascade face detector, which is a classifier trained on
human faces.
Visual Studio - Visual Studio is used to build and run solution examples after properly
configuring EmguCV. The desktop software will implement two sub-systems (Training Set
Manager and Face Recognizer), along with the face detector in a Windows form.
In this way, both mobile and desktop tools will be used to complete the system design.
2.6.3 PROJECT#3
In 2019, a student from the Electrical Engineering department at Prince Muhammad Bin Fahd University
worked on a face recognition attendance system. He used LabVIEW programming and the LabVIEW
10
Vision module. He believed that LabVIEW programming and LabVIEW Vision are not only the best for
pattern matching, but can also be used to implement other machine vision techniques like edge tracking
and geometric matching. His main goal was to automate the attendance system, save valuable class time,
and prevent errors that occur with manual attendance systems
The following flowchart illustrates how information flows throughout the entire process:
In our project, we are using MySQL database to store the data. For face detection, we are using the Haar
Cascade Classifier, which is best for real-time face detection. We have also used custom face cropping,
which crops the detected face from the image for further processing. For face recognition and training,
we have used LBPH (Local Binary Pattern Histogram), which is implemented in OpenCV.
11
In this way, our project is a bit different from the previous one.
12
Chapter 3
3.1 Introduction
This chapter intends to analyze in-depth the requirements for the Face Recognition System, which
automates the student attendance process through facial recognition technology. This system is to be
made efficient in educational environments in eliminating the need for taking attendance through manual
methods. This chapter discusses functional requirements, nonfunctional requirements, and system
requirements based on the features presented in the modules of the system.
The FRS has different interdependent modules; every module performs a specific task. These modules
have functions of user authentication, record for students, face recognition, attendance, and help features
from users. This analysis of these modules will make it explicit regarding the required features and the
working requirement of the system.
17
3.7 Methodology
We used the agile methodology for developing the Face Recognition Attendance System. Agile is very
ideal for projects where flexibility, iterative development, and development are necessary; that's why
requirements may change. And since this project needed that characteristic of evolution, we applied the
agile methodology.
18
to the facial data stored in the system. The system utilizes the LBPH (Local Binary Pattern Histogram)
face recognition algorithm, which is a traditional method based on texture patterns for facial recognition.
3.7.3.1 Step 1: Face Detection
The first step in this process is face detection in an image. This is made possible by the use of Haar
Cascades. It is one of the commonly used object detection methods of OpenCV. The face is likely to be
detected in regions of the image by the Haar Cascade classifier.
3.7.3.2 Step 2: Feature Extraction
Once the face is detected, the system will extract the facial features using the LBPH algorithm. The
LBPH method analyzes the texture in a local neighborhood around each pixel to capture local patterns
and encode them into a histogram that represents the face features. The features are stored as a unique
identifier for each face.
3.7.3.3 Step 3: Compare Faces
The extracted features from the live face image are matched against the stored facial data in the database.
In general, it is performed through the Euclidean distance between the histograms of the detected face
and the stored faces. A small enough distance is used to conclude the successful recognition, as long as
the match confidence is high.
3.7.3.4 Step 4: Attendance Marking
In case a match is found, the system automatically records the student's attendance by logging the
student's ID along with the current date and time. All these data are kept for further reference and
reporting.
3.8 Summary
This chapter has discussed the detailed requirement analysis of the Face Recognition Attendance System
in terms of functional requirements, non-functional requirements, software requirements, and hardware
requirements. The selected agile development methodology was explained, thus giving a structured and
systematic approach for the design, development, and implementation of the system. Additionally, some
key tools and technologies to be used in the development process and the face recognition algorithm
have been emphasized. In the following chapter, the detailed design of the system will be presented.
19
Chapter 4
4 SYSTEM DESIGN
The database should have more samples to improve detection efficiency. Additionally, the more
expensive the camera, the easier it will be for its algorithm to recognize people.
The camera should be able to capture all the students in the class. Every student should be seated in a
way that they are visible to the camera, so their attendance can be marked easily.
Another ethical issue is related to a person's physical appearance. If someone changes their look and
appears different in their photo from what they look like in person, it may be difficult to mark their
attendance.
4. A face detection algorithm will be used to find the face in the image.
5. Specific features from the detected face will be extracted using the algorithm.
20
6. The training image will be saved in classifier.xml file.
7. Next, a face recognition algorithm will check if the face is already stored by comparing the
features.
4.3.1 Overview
Our project uses a My SQL database to store the following information.
1. User: it stores personal information along with their face images.
2. Student Records: it is use to stores information about students including their IDs, face images for
recognition and their names.
3. Training Data: it is used to store information for training the recognition model , which is derived
from student images.
21
email:
password:
SQL Queries:
CREATE TABLE user_data (
id INT AUTO_INCREMENT PRIMARY KEY,email VARCHAR(100) UNIQUE,username
VARCHAR(100),password VARCHAR(100),face_image VARCHAR(255)
);
23
Figure 10: TRAINING DATA TABLE
Key Relationship:
User’s → Training Data (One-to-Many)
Student’s → Training Data (One-to-Many)
Tkinter is Used for creating the GUI elements and PIL (Python Imaging Library) is Used to load and
manipulate images, particularly for resizing images that will be displayed in the GUI.
24
A background image is added using the Label widget and displayed across the entire window.
The image is loaded with ImageTk.PhotoImage().
Main Frame:
A Frame widget is used as the container for other widgets, with a white background. This frame
is positioned inside the main window.
Input Fields:
Email, username, password, confirm password are used for input field.
Signup Button:
A Button widget labeled "Signup" is provided for submitting the form. When clicked, it triggers
the function connect_database, which handles user registration and interaction with the database.
Login Button:
A Button labeled "Login" is provided, which when clicked, calls the login_page function to
navigate the user to the login page.
Each button in the frames opens a new window related to a specific subsystem:
Student Details (Student): Opens a new window that handles student data management.
Photos (open_img):
• Opens a window to train the face recognition system with new data.
• Opens a window that detects faces using the face recognition model.
Attendance (Atendence):
Developer (Developer):
Help (Help):
Exit (exit_program):
• Asks the user to confirm whether they want to exit the application and closes the window if
confirmed.
27
Figure 13: SCREENSHOT OF MAIN WINDOW
The GUI of the Student Management System with Face Recognition consists of the following main
components:
Main Window: The window is set with a title "Face Recognition System" and has a size of 1530x790.
Image Display:
• The top section of the window includes three images displayed horizontally, while a large
background image occupies the rest of the space.
Frames:
• Main Frame: It is the primary container for the layout, which is divided into left and right
sections.
• Left Frame: This frame contains the form for entering student details, including fields for student
ID, name, department, year, and semester. It also includes radio buttons to select whether to take
a photo sample.
• Right Frame: This area displays a table (using a Treeview widget) to show the list of students
with columns for student details, such as ID, name, department, and photo sample status.
Widgets:
28
• Labels: Used for displaying text such as "Department", "Name", "Roll Number", etc.
• Entry Fields: Allow the user to input student details like ID, name, phone number, etc.
• Comboboxes: Dropdown menus for selecting the department, year, and semester.
• Radio Buttons: Allow the user to choose between taking a photo sample or not.
• Buttons: Buttons for saving, updating, deleting, and resetting student information, as well as a
button for capturing photo samples.
Table (Treeview):
• Displays the list of student records, showing relevant details like department, year, semester, and
photo sample status. It includes both horizontal and vertical scrollbars for navigation.
The GUI of the Student Management System with Train Photos consists of the following main
components:
Window Setup:
• The window is created using the Tk() instance, and the root window is sized to 1530x790 pixels.
• The window title is set to "Face Recognition System".
Label for Title:
• A title label "TRAIN DATA SET" is placed at the top of the window with a custom font and
background color.
Top Image:
• The top image is displayed below the title label. It is resized using the Python Imaging Library
29
(PIL) and is set as the background for a label.
Train Data Button:
• A button labeled "TRAIN DATA" is provided. When clicked, it triggers the train_classifier()
function to start the face recognition model training.
Bottom Image:
• Another image is placed at the bottom part of the window, using the same process of resizing and
displaying as the top image.
The GUI of the face recognition window System of the following main components:
Main Window:
• The root window is created using the Tk() instance, and it is configured with the title "Face
Recognition System", and a resolution of 1530x790 pixels.
Title Label:
• A label is placed at the top to display the title "FACE DETECTION AND RECOGNITION" in a
large font, with custom background and foreground colors.
Images:
30
• Top Image: A large image is displayed at the top using the PIL library for resizing and displaying
the image.
• Right Image: Another image is displayed to the right side of the screen.
The GUI of the Attendance Windows with Face Recognition consists of the following main components:
Main Window:
• The main window serves as the container for all other elements. It is sized at 1530x790 pixels,
which is quite large to accommodate various sections of the interface.
• The background includes images, such as a school-themed banner and a title header.
• The title of the window is set as "Face Recognition System" and is displayed prominently at the
top.
31
Layout:
Interactivity:
• The system allows importing and exporting attendance data using CSV files.
• The table supports interactions, where clicking on a row can load the selected record into the
input fields in the left section.
This GUI is designed to be user-friendly and intuitive, with sections clearly separated for data entry and
displaying attendance records. It is part of a broader system where students' attendance is monitored
using facial recognition technology.
The GUI of the Help disk widows with Face Recognition consists of the following main components:
• Window Size: The window is set to a large size (1530x790 pixels) to ensure that all the elements
fit comfortably without appearing too cramped. This is appropriate for displaying both images
and text clearly.
32
• Window Title: The window’s title is set to "FACE RECOGNITION ALGORITHM," indicating
the purpose of the program.
Title Label:
• Label for Title: A label at the very top of the window is used to display the text "Help Desk" in a
large, bold font (35px, "Times New Roman"). This label serves as the heading of the help desk
section of the GUI.
• Background Color: The title has a white background, making the text stand out.
• Position: It is placed at the top-left corner of the window, occupying the full width but with a
height of 45 pixels.
Top Image:
• Background Image: The window includes a large background image, which occupies the area
from (0, 55) to the bottom of the window (1530x720 pixels).
• Image Handling: The image is loaded using the Pillow (PIL) library. It is resized to fit the
window’s dimensions while maintaining the aspect ratio to ensure it does not get distorted.
• Image Purpose: The image appears to be related to the face recognition topic, perhaps illustrating
the concept of the algorithm or showing something visually related to the system, such as an
example of face recognition.
• Canvas Widget: A Canvas is used to overlay text and other elements over the background image.
It is a powerful widget in Tkinter that allows for drawing shapes, displaying text, and adding
images in a customized way.
• Canvas Placement: The canvas is placed on top of the background image, covering the entire area
of the image (1530x720).
Text Elements:
• The canvas contains a "For assistance, please contact:" text at the center, using an italic font
(20px) with black text color. This serves as an instruction to the user, telling them how to get help
33
or support.
• Below this text, there is a label displaying the developer's contact email
("[email protected]"). This email is prominently displayed in a blue font, providing a
clear method for users to reach out for assistance.
• Contact Details: My email address is placed at the bottom of the canvas using a bold, blue-
colored font. This section provides users with a direct way to contact the developer for help or
further questions.
• Font Style: The text is rendered in "Times New Roman" font (30px), making it large enough to
be noticeable but not overwhelming.
• Positioning: The email is centered in the window, positioned at (500, 520) on the canvas. The text
is positioned clearly and prominently for the user to easily spot it.
User Interaction:
• The GUI is designed to be relatively simple and minimalistic. It does not contain interactive
elements like buttons or input fields since its primary function is to provide information (the
contact information and the purpose of the application).
• Static Display: The primary interactive aspect is the display of information about the help desk
and the contact email for assistance. There is no active interaction required from the user beyond
viewing the information.
34
4.4.10 Developer module (developer.py)
The GUI of the Help disk widows with Face Recognition consists of the following main components:
Main Window Setup:
• Window Size and Position: The window is set to a large size (1530x790 pixels), which is
spacious enough to accommodate both images and text.
• Window Title: The window is titled "Face Recognition System" to indicate the purpose of the
program.
Title Label:
• The title "DEVELOPER" is displayed at the top of the window using a large, bold font (30px) in
green color. This label helps in identifying the section of the app that provides details about the
developers.
• The title is placed in a white background and spans the full width of the window (1530px) with a
height of 45px.
Top Image:
• A large background image is loaded using the Pillow (PIL) library and displayed in the window.
The image is resized to fit the width and height of the window (1530x720 pixels).
• This image, which could be a relevant visual or backdrop related to the project, serves as the
background for the developer information section.
Frame for Developer Info:
• A Frame widget is created inside the background image container to hold the developer details.
This frame is positioned at (1050, 0) with a width of 500px and height of 710px, taking up a
portion of the window on the right side.
• The background color of the frame matches the background color of the image, creating a
seamless visual integration.
Developer Image:
• Within the frame, an image of the developer (possibly a logo or profile picture) is loaded and
resized to 200x200 pixels. This image is placed at the top-right corner of the frame.
• The image is displayed as a Label and serves to visually represent the developers.
Developer Information Labels:
• Several labels are used to provide detailed information about the developers:
• Greeting and Introduction: The first labels welcome the user and greet them with "Assalamu
35
Alikum" and "Welcome to Developer section."
• App Information: Subsequent labels explain that the app is collaboration between the developer
Zia and Zuhaib.
• Each label uses a bold font (15px) and is placed at different vertical positions in the frame to
ensure that the information is displayed in a clear and organized manner.
• The text color is dark blue, and the background color matches the frame's background, ensuring
the content blends well with the overall design.
Additional Developer Image:
• Another image is added below the developer details to further enrich the content. This image is
resized to 500x510 pixels and is placed below the developer information labels.
• Window Size and Position: The window is set to a large size (1530x790 pixels), which is
spacious enough to accommodate both images and text.
36
Chapter 5
5 SYSTEM IMPLEMENTATION
5.1 Introduction
In this chapter, we will examine the implementation of our Face Recognition System. This system
integrates several components, such as sign-up, login, face recognition, and more. All these components
are interconnected and work together to complete the system. We developed the Face Recognition
Attendance System using Python, and various libraries were used, such as Tkinter for the GUI, OpenCV
for image processing, PIL library for image handling, and MySQL. connector for database interaction.
We will thoroughly explore all of these libraries in this chapter.
37
5.3 Libraries and algorithms
In our project, we have used different libraries such as Tkinter, OpenCV, PIL, and various algorithms
like LBPH and Haar Cascade Classifier. These libraries and algorithms have been used in our modules to
ensure that the system works efficiently and provides the correct output. are used in our project
5.3.1 Tkinter
Tkinter is a standard library in Python used for creating graphical user interfaces (GUIs). For this reason,
we have used Tkinter in every module of our project. Tkinter provides various widgets such as labels,
frames, and other components that we have used in our system.
Importing tkinter: To use Tkinter, we first import it as follows:
Code:
from tkinter import *
from tkinter import ttk
In the beginning of each module, i import tkinter for creating the graphical interface. The ttk module is
used for more modern widgets like comboboxes and styled buttons etc.
5.3.1.1 Creating the Main Window
In my project each of the modules like Signup.py, Login.py, Attendance.py,main.py etc., I set up the
main window where all other widgets (buttons, labels, tables, etc.) are placed. For example, my all
module I use this line of code:
Code:
self.root = Tk()
self.root.geometry("1530x790+0+0") # Define the window size
self.root.title("Face Recognition System") # Set the title of the window
• Tk() it is used to initializes the main window.
• geometry () through this I sets the window's size.
• title () this gives a title to the window.
5.3.1.2 Creating Widgets
Widgets in Tkinter are the building blocks of any GUI. They are used to display information and interact
with the user. Some examples from my code:
Labels: I used labels for displaying text or images in my system.
Code:
38
title_lbl = Label (self.root, text="Help Desk", font=("times new roman", 35, "bold"), bg="white")
title_lbl.place(x=0, y=0, width=1530, height=45)
• Label () creates a label widget with specified text, font, and background color.
• place () is used to position the widget at specific coordinates.
Entry (Textboxes): In my project I used Entry for taking input from the user (like in login, signup,
attendance entry).
Code:
attendance_entry = ttk.Entry(leftInsdide_frame, textvariable=self.var_atten_id, font=("times new
roman", 11, "bold"))
attendance_entry.grid(row=0, column=1, padx=15, pady=9)
• Entry () creates a textbox where the user can type text.
• grid () arranges widgets in a grid layout with specific rows and columns.
Buttons: This are also Used in my project to trigger actions like submitting data, importing/exporting
CSV files, etc. below line of code are used in my project.
Import_csv_btn = Button (btn_fram, text="Import csv", command=self.importCSV, font=("times
new roman", 17, "bold"), width=17, bg="red", fg="white", activebackground="yellow")
Import_csv_btn.grid(row=0, column=0, padx=0)
• Button () in my project it is use to creates a button widget, with text, and an action defined by the
command parameter.
• When clicked, this button calls the method importCSV().
Combobox: In my project Combobox are Used for selecting options from a list (e.g., Attendance status:
Present/Absent). Below line of code is part of my project.
dep_combo = ttk.Combobox(leftInsdide_frame, textvariable=self.var_attend, font=("times new roman",
10, "bold"), state="readonly")
dep_combo["values"] = ("Status", "Present", "Absent")
dep_combo.current(0)
dep_combo.grid(row=3, column=1, padx=2, pady=10)
• Combobox() allows the user to select a value from a dropdown list.
39
process images. We have used PIL in various modules like signup.py, login.py, main.py, student.py, and
others.
5.3.2.1 PIL Library Overview
This library is used for opening, manipulating, and saving various image file formats. In my project, it is
primarily used for:
1. Image resizing and conversion.
2. Displaying images within the GUI (Tkinter).
3. Handling image files for face recognition, capturing images, and processing them.
5.3.2.2 PIL Functionality in Different Modules
main.py (Main GUI and Image Display): In this module, we have used the PIL library. We have used
the PIL library in two important places. Below is the code that we have used in our module.
Code:
img3 = Image.open(r"C:\Users\HP\Desktop\New folder\547464.jpg")
In this, we have used a function, Image.open(). The function's job is to open an image from a specific
path and display it on the system.
Additionally, we have used another place, which is as follows:
Code:
img3 = img3.resize((1537, 780), Image.LANCZOS)
After the image is loaded, the resize () method is used to resize the image to the dimensions 1537x780
pixels. The second argument, Image.LANCZOS, specifies the resampling filter to be used for resizing.
LANCZOS is a high-quality resampling filter that produces smooth results when resizing images.
Student.py: This module, we have also used the PIL library. The two important uses we have
implemented in our module are explained through the code below:
Code:
img = Image.open(r"C:\Users\HP\Desktop\New folder\morskie-oko-tatry.jpg")
The Image.open() function is used to open an image file from specific location. Another use PIL library
in student.py module is:
Code:
self.photoimg = ImageTk.PhotoImage(img):
The ImageTk.PhotoImage() function is used to convert the PIL image into a format that can be displayed
by Tkinter
FaceRecognition.py: In this module, we have also used the PIL library to open an image using the
40
image.open() function. Additionally, we have used PIL to resize the image by applying the
image.resize() function. Another usage is shown in the code below.
Code:
f_lbl = Label (self.root, image=self.photoimg_top)
f_lbl.place(x=0, y=46, width=735, height=690) # Display the resized image on the Tkinter window
The above code has been written in our module to display the resized image.
Train.py: The PIL library is also used in the Train.py module because image processing is involved in
this module as well. In this module, we used the image.open() function to open an image. Additionally,
the image.resize() function was used to resize the image according to the window dimensions.
Furthermore, to display the image, we used the following code with a label.
Code:
self.photoimg_top = ImageTk.PhotoImage(img_top). This is done so the image can be displayed
properly. We also used PIL for another purpose, as shown in the code below
.
img = Image.open(image). convert('L’) # Convert image to grayscale
image_np = np.array(img, 'uint8') # Convert to numpy array for OpenCV
In this line of code, we first converted the image to grayscale so that the image can be set for training.
Attendance.py:In this module, we used the image.open() function to open the image. Additionally, we
resized the image using the following code: Img.resize((800, 330), Image.LANCZOS). We also used PIL
in this module to convert the image into a Tkinter-compatible format, like this.
Code:
self.photoimg = ImageTk.PhotoImage(img).
Help.py and developer.py: In both of these modules, we used PIL for the following tasks:
• To open the image.
• To resize the image.
• To convert the image into a Tkinter-compatible format.
• To display the image.
5.3.3 OpenCv
OpenCv is a huge open-source library for computer vision, machine learning, and image processing.
Now, it plays a major role in real-time operation which is very important in today’s systems. By using it,
41
one can process images and videos to identify objects, faces, or even the handwriting of a human.
We have used OpenCV within our system for image processing because this library is very important for
face recognition systems. We have used this library for various tasks such as face detection, opening the
camera, releasing the camera, training the face, recognizing the face, and many other functions. Through
this, we will see step by step which tasks we performed and how we did them, with the code that we used
in our different modules. (Kiran, 2022)
5.3.3.1 Face Detection
The primary OpenCV functionality used for face detection in my code is the Haar Cascade Classifier.
Loading the Cascade Classifier:
The Haar Cascade Classifier is a pre-trained model that is used to detect faces in images or video frames.
It is loaded using the cv2.CascadeClassifier() method, which loads an XML file containing the trained
face detection model. I have used this for load the cascade classifier by using the code provided below.
Code:
face_classifier = cv2.CascadeClassifier("C:\\Users\\HP\\Desktop\\my project\\
haarcascade_frontalface_default.xml")
Detecting Faces: After loading the classifier,we use in our module the method detectMultiScale() is
used for face detection from the given image. The function detectMultiScale() accepts the image in
grayscale form as input and returns a list of rectangles where faces have been detected. . I have used this
for face detection by using the code provided below.
Code:
faces = face_classifier.detectMultiScale(gray, 1.3, 5)
5.3.3.2 Cropped Face Image:
The faces detected are represented by rectangular coordinates (x, y, w, h) and are used to crop the region
of interest (ROI) from the image. This cropped face can then be processed further (e.g., resized or
saved).we use the bellow line of code to achieve this.
Code:
face_cropped = img[y:y+h, x:x+w]
5.3.3.3 Opening the Camera:
OpenCV cv2.VideoCapture() is used in my student detail module to open the default camera to capture
video frames. The 0 parameter indicates the default camera, but it can be changed to select other
connected cameras. I use the below line of code to open camera.
Code:
42
cap = cv2.VideoCapture(0) # Open default webcam
5.3.3.4 Capturing Frames
The cap.read() function is used in student.py to capture each frame from the camera in real-time. It
returns a boolean (ret) to indicate success and the current frame (my_frame). I use the below line of code
to capture frame.
Code:
ret, my_frame = cap.read()
5.3.3.5 Displaying Captured Frames
OpenCV's cv2.imshow() is used in my module student.py to display the captured frames (or processed
frames) in a window. In my case, it shows the cropped faces as they are detected. Below line of code use
in my module:
Code:
cv2.imshow("Cropped Face", face)
5.3.3.6 Saving the Captured Face Images
After detecting a face, we save captured image. The script saves it as a grayscale image. File path is
dynamically generated with respect to user ID and image ID. This line of code I use in my module.
Code:
cv2.imwrite(file_name_path, face)
The image is saved into the folder defined by the path "C:\\\Users\\\HP\\\Desktop\\my project\\data\\
user." + str(id) + ".\\\" + str(img_id) + ".jpg"
5.3.3.7 Exiting the Capture Loop
The loop captures images until the user either presses the Enter key (key code 13) or until 200 images
have been captured. This ensures the process stops after capturing a set number of face images. Below
line of code are use in my system.
Code:
if cv2.waitKey(1) == 13 or int(img_id == 200): # Exit on Enter or after 200 images
break
5.3.3.8 Image Processing
Image processing is the most important part of face recognition. We have used it in our student detail
module to convert the image into grayscale.
Converting to Grayscale:
The captured face image is converted to grayscale using cv2.cvtColor(), which is essential for face
43
recognition tasks. We use this below line of code to convert face image to grayscale.
Code:
face = cv2.cvtColor(face, cv2.COLOR_BGR2GRAY)
Resizing the Cropped Face:
The cropped face is then resized to a fixed dimension of 450x450 pixels for uniformity before it is saved
or processed. For that, we wrote this line of code in student.py.
Code:
face = cv2.resize(face, (450, 450))
5.3.3.9 Camera Release
After the face detection and data capture process, we released the camera using cap.release(), which is
important for cleaning up resources and freeing the camera device.
Code:
cap.release()
44
Code:
clf.write(output_path) # Save the trained model to the specified file path
Loading the Trained Classifier
Now we load the trained classifier. This function loads the previously trained classifier from the XML
file for later use in face recognition. In train.py the code appear like below.
Code:
clf.read(output_path) # Load the trained classifier from file
Provide for regular updates of the system by adding new features as well as security patches.
46
Chapter 6
47
6.2.3 UAT
The stakeholders carried out UAT for the confirmation of the system's functionality and usability. The
stakeholders verified that the facial recognition was working correctly and that the attendance was
recorded correctly by testing the system.
6.3.5 Security
The system was secure, and access to sensitive data was restricted to authorized personnel only. No
vulnerabilities were found during the testing.
48
6.4 Conclusion
The system has gone through all the major testing steps and has proven its ability to automate attendance,
generate very accurate reports, and even operate securely. Though some things could be done better; for
example, managing multiple users at once and improving its performance in dimly lit environments, the
system is good enough to be a point of departure for future development.
50
Chapter 7
7.1 Conclusion
By using facial recognition technology, the Face Recognition Attendance System effectively automates
the attendance process, minimizing errors and manual efforts. The system uses Python and OpenCV to
detect and recognize faces, making it a simple and reliable way to manage attendance in schools,colleges
and universities and can be used offices as well. The project achieved its main goals and provided
valuable possibilities for learning about machine learning, programming, and system development. Even
though the system has some limitations, like trouble recognizing faces in low light or in partially
blocked, it is a good starting point for improving attendance management technology.
51
different sectors.
8 References
o (n.d.).
o Gautam Buddh Nagar, U. P. (2024, 1022). Retrieved from GeeksforGeeks:
https://www.geeksforgeeks.org/functional-vs-non-functional-requirements/#functional-
requirements
o Gonnet, G. (2012, 01 02). opentext. Retrieved from OpenText: https://www.opentext.com/what-
is/performance-testing#:~:text=Performance%20testing%20is%20a%20non,up%20under%20a
%20given%20workload.
o Howse, J. (2020). OpenCV for Secret Agents. Cincinnati, OH.
o Kiran, M. a. (2022, 4 1). Automated Face Recognition Attendance System using Python Oand
OpenCV.
o Krüger, G. (22, 7 2012). PERFORCE. Retrieved from perforce:
https://www.perforce.com/blog/alm/what-are-non-functional-requirements-examples#what-are-
non-functional-requirements
o Rosebrock, A. (2020). Prectical Pyhton and OpenCv. uk.
o University, R. a. (2023, 2 5). Face Recognization Based Attendance System Using Haar Cacade
and LBPH.
52