0% found this document useful (0 votes)
133 views45 pages

Industrial Report

industrial training report on project Face Recognition System for Btech

Uploaded by

Pratham Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views45 pages

Industrial Report

industrial training report on project Face Recognition System for Btech

Uploaded by

Pratham Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Department of Computer Science and Technology

School of Engineering and Technology

HEMVATI NANDAN BAHUGUNA GARHWAL UNIVERSITY

SRINAGAR, UTTRAKHAND, 246174

SESSION: 2020-24

A Report of Internship Project on


FACE RECOGNITION SYSTEM
USING PYTHON

SUBMITTED TO SUBMITTED BY

Mr. VIJAY P. BIJLWAN PRATHAM SHARMA

Assistant Professor 20134501031

Dept. Of CSE
DECLARATION

On the very outset of this report, I, Pratham Sharma of CSE branch in HNB
Gharwal University, would like to extend my sincere and heartfelt gratitude
towards my respected teacher Mr. Vijay P. Bijlwan, whose help, stimulating
suggestions and encouragement helped me in writing this report.

I have tried my best to elucidate every important and relevant detail in the
report.

I further declare that the reported work in this project has not been submitted
and will not be submitted, either in part or in full, for the award of any other
degree in this institute or any other institute or university.

Date: 27/11/2023 Pratham Sharma (20134501031)

Place: HNBGU, Srinagar

1
CERTIFICATE

This is to certify that, this Industrial training report submitted by Pratham


Sharma bearing roll no 20134501031, is bonafide record of the work carried out
by them in partial fulfilment for the requirement of the award of Bachelor of
Technology in Computer Science and Engineering degree from Hemvati Nandan
Bahuguna Garhwal University (A Central University) at Srinagar (Garhwal),
Uttarakhand.
Mr. Vijay P. Bijlwan
Department of Computer Science & Engineering
Hemvati Nandan Bahuguna Garhwal University (A Central University)
Srinagar (Garhwal), Uttarakhand

2
ACKNOWLEDGEMENT

I would like to express my deepest gratitude to all people for sprinkling their
help and kindness in the completion of this Project. I would like to start this
moment by invoking my purest gratitude to Mr. Vinay Kant our project
instructor at NIELIT HARIDWAR.
I would also like to express my deepest gratitude towards Mr. Vijay P. Bijlwan
for always supporting and encouraging me in trying out new things and
challenging my limits.
The completion of this project could not have been possible without their
expertise and invaluable guidance.

3
ABSTRACT

The face is one of the easiest ways to distinguish the individual identity of each
other. Face recognition is a personal identification system that uses personal
characteristics of a person to identify the person's identity. Human face
recognition procedure basically consists of two phases, namely face detection,
where this process takes place very rapidly in humans, except under conditions
where the object is located at a short distance away, the next is the
introduction, which recognize a face as individuals.

Stage is then replicated and developed as a model for facial image recognition
(face recognition) is one of the much-studied biometrics technology and
developed by experts. of the face image. The area of this project face detection
system with face recognition is Image processing. The software requirements
for this project is OpenCV software.

4
CONTENTS

CANDIDATE’S DECLARATION………………………………………………………….1

CERTIFICATE………………………………………………………………………………2

ACKNOWLEDGEMENT.…………………………………………………………………..3

ABSTRACT……………………………………………………………………………….….4

ABOUT ORGANIZATION-NIELIT……………………………………………………..7-8

EXPERIENCE……………………………………………………………………………9-10

CHAPTER 1: INTRODUCTUION…………………………………………………….11-12

1.1 PROJECT AIM AND OBJECTIVES…………………………………………….11


1.2 BACKGROUND OF PROJECT………………………………………………….12

CHAPTER 2: LITERATURE REVIEW…..…………………………………………....13-14

2.1 FACE RECOGNITION TECHNIQUES.....………………………………………,,13


2.2 PYTHON AND FACE RECOGNITION…………………………………………...14

CHAPTER 3: SETTING UP ENVIRONMENT...………………………………………15-16

CHAPTER 4: SYSTEM ARCHITECTURE………………………………………………..17

CHAPTER 5: OPENCV LIBRARY……………………………………………………18-22

5.1 IMAGE AS ARRAYS………………………………………………………........18


5.2 CLASSIFIERS……………………………………………………………..……..19

CHAPTER 6: FACE DETECTION IN REAL TIME VIDEO STREAMS…………23-25

CHAPTER 7: CHALLENGES…………………………………………………………26-27

CHAPTER 8: FUTURE SCOPE……………………………………………………….28-30

5
CHAPTER 9: ETHICAL CONSIDERATIONS………………………………………….31

CHAPTER 10: PROJECT IMPLEMENTAION………………………………...……32-40

10.1 PROJECT SOURCE CODE………………….…………………………………32


10.2 PROJECT OUTPUT………………………….…...…………………………….38

CONCLUSION……………………………………………………………………………...41-43

REFERENCES…………………………………………………………………………………44

6
ABOUT ORGANIZATION-NIELIT

National Institute of Electronics and Information Technology (NIELIT) is an


autonomous scientific society under the administrative control of Ministry of
Electronics and Information Technology (MeitY), Government of India. NIELIT is
actively engaged in Capacity Buildingand Skill Development in the areas of
Information Technology (IT); Electronics; Communication Technologies;
Hardware; Cyber Law; Cyber Security; Geographic Information System (GIS);
Cloud Computing; Electronics System Design & Manufacturing (ESDM); e-
Waste; Internet of Things (IoT); Big Data; Block Chain; Data Analytics; e-
Governance and related verticals. It offers courses both in Formal as well as
Non-Formal Sectors and is also one of the National Examination Bodies. NIELIT
accredits institutes/ organizations for the conduct of courses in the Non-Formal
Sector. NIELIT is also rolling outIT Literacy Programmes for many State
Governments for its employees and the masses. NIELIT is also entrusted by
many organizations to conducts their recruitment examinations.NIELIT
conducting Online examinations and Third-party assessments of courses.

NIELIT undertakes various projects under Capacity Building in IECT with the
objective of creating human resources at various levels, which includes
employment and self-employmentlinked quality and cost-effective training
programmes. Besides, NIELIT also conducts IT Literacy programmes for the
masses, targeted towards the rural/ underdeveloped areas in the country.

NIELIT is functioning under the overall control and guidance of the Governing
Council. Thehon’ble Union minister for Electronics and Information Technology
(E&IT) is the Chairpersonof the Governing Council and the Hon’ble MoS (E&IT)
is the Deputy Chairperson. The other members of the Governing Council are
drawn from Government, Industry, Academia and representatives of various
professional bodies.

The Management Board of NIELIT is chaired by the Secretary, Ministry of


Electronics and Information Technology (MeitY), Government of India.
Each NIELIT Centre has an Executive Committee consisting of
7
representatives from respective State Governments, Academic Institutions and
Industry for effective implementation of the decisions of theManagement
Board and the Governing Council.

I complete my internship from NIELIT HARIDWAR and my mentor is MR. VINAY


KANT (MTech in ML from IIT JODHPUR)

8
EXPERIENCE

When undergoing industrial training at NIELIT (National Institute of Electronics


and Information
Technology) or any other institution, it's crucial to approach the experience with
professionalism and integrity. Here are some general tips to ensure a positive
and plagiarism-free industrial training experience:
Understand the Guidelines:
Familiarize yourself with the guidelines and expectations of the industrial
training program. Ensure you are aware of any specific rules regarding
documentation, project submissions, and plagiarism policies.
Original Work:
Always produce original work. If you are working on a project or assignment,
avoid copying content directly from external sources without proper citation.
Plagiarism is a serious offense and can have consequences on your academic
and professional reputation.
Cite Sources Properly:
If you need to include information from external sources, make sure to cite
them properly using the appropriate citation style (e.g., APA, MLA, Chicago).
This applies to text, images, code, or any other content that is not your own.
Seek Guidance:
If you are unsure about how to approach a particular task or project, don't
hesitate to seek guidance from your mentors, supervisors, or instructors. They
are there to support you and can provide valuable insights.
Regular Updates:
Keep your mentors and supervisors informed about your progress. Regular
updates on your work will help them understand your efforts and contributions
to the project.
Feedback and Revisions:

9
Be open to receiving feedback on your work. If your mentors suggest revisions
or improvements, take their feedback seriously and make the necessary
changes. This demonstrates a willingness to learn and improve.
Time Management:
Manage your time effectively to meet project deadlines. Procrastination can
lead to rushed and potentially plagiarized work.

10
CHAPTER 1: INTRODUCTION

Face recognition is an easy task for humans. Experiments have shown, that
even one month old babies are able to distinguish between known faces. So
how hard could it be for a computer? It was shown by David Hubel and Torsten
Wiesel, that our brain has specialised nerve cells responding to specific local
features of a scene, such as lines, edges, angles or movement. Since we don't
see the world as scattered pieces, our visual cortex must somehow combine
the different sources of information into useful patterns.

Face recognition is the task of identifying an already detected object as a


known or unknown face. Often the problem of face recognition is confused
with the problem of face detection. Face Recognition on the other hand is to
decide if the "face" is someone known, or unknown, using for this purpose, a
database of faces in order to validate the input face.

1.1 Project Aims and Objectives

The primary objective of this project is to develop a robust and accurate face
recognition system using the Python programming language. The system aims
to leverage computer vision and machine learning techniques to automatically
identify and authenticate individuals based on their facial features. The project
will tackle challenges commonly associated with face recognition systems,
including variations in lighting conditions, facial expressions, pose, and
occlusions.

By achieving these objectives, this project aims to contribute to the


advancement of face recognition technology and provide a reliable and
efficient face recognition system using the Python programming language.

11
1.2 Background of Project
Face recognition technology has gained significant attention in recent years due
to its wide range of applications in various domains, including security,
surveillance, access control, and biometric authentication. The ability to
automatically identify and authenticate individuals based on their unique facial
features has revolutionized the way we interact with technology and the
physical world. The development of face recognition systems can be traced
back to the early 1960s. Over the decades, significant advancements have been
made in computer vision, machine learning, and deep learning, leading to
more accurate and robust face recognition algorithms. Initially, face recognition
systems relied on traditional computer vision techniques. These methods
focused on extracting the most discriminative facial features and comparing
them against a stored database of known faces. While these early systems
showed promising results, they were limited by factors such as variations in
lighting conditions, facial expressions, and pose, which often led to false
positives or negatives. The emergence of deep learning algorithms has
revolutionized the field of face recognition. Python, with its rich ecosystem of
libraries and frameworks, has become a popular programming language for
implementing face recognition systems. Libraries such as OpenCV, TensorFlow
provide powerful tools for image processing, facial feature detection, and deep
learning-based face recognition. Considering the increasing demand for reliable
and efficient face recognition systems, this project aims to develop a face
recognition system using Python. By understanding the intricacies of face
recognition systems and their implementation using Python, we can pave the
way for enhanced security, convenience, and efficiency in various industries
and everyday life.

12
CHAPTER 2: LITERATURE REVIEW

The field of face recognition has been extensively studied, resulting in a rich
body of literature that explores various techniques, algorithms, and
applications. This section provides an overview of the key research works and
advancements in the field of face recognition.

2.1 Face Recognition Techniques


Traditional face recognition techniques, such as Eigenfaces, Fisherfaces, and
Local Binary Patterns (LBP), have been widely explored in the literature.
Eigenfaces, based on Principal Component Analysis (PCA), aim to extract the
most discriminative facial features by representing faces as linear combinations
of eigenfaces. Fisherfaces, using Linear Discriminant Analysis (LDA), focus on
maximizing the ratio of between-class scatter to within-class scatter for
improved classification. LBP encodes local texture patterns and has shown
robustness to variations in lighting and facial expressions. In recent years, deep
learning-based approaches have gained significant attention and achieved
remarkable performance in face recognition. Convolutional Neural Networks
(CNNs) have become a popular choice due to their ability to automatically learn
hierarchical representations of facial features. DeepFace, proposed by
Facebook, employs a deep CNN architecture to directly learn face embeddings
for identification. FaceNet, introduced by Google, uses a siamese network and
triplet loss to learn a mapping from face images to a high-dimensional feature
space where faces of the same identity are close together and faces of different
identities are far apart.

13
2.2 Python and Face Recognition

Python programming language, with its extensive libraries and tools, has
become a go-to choice for implementing face recognition systems. OpenCV, a
popular computer vision library, provides a wide range of functionalities for
facial detection, feature extraction, and image manipulation. Dlib, another
notable library, offers facial feature detection, including landmark detection
and face alignment, which are vital for accurate face recognition. Python's deep
learning frameworks, such as TensorFlow, PyTorch, and Keras, have also played
a significant role in advancing face recognition. These frameworks provide tools
for training and deploying deep neural networks, including CNN architectures
suitable for face recognition tasks. The availability of pre-trained models and
the flexibility to fine-tune them for specific datasets have facilitated the
development of accurate and efficient face recognition systems. Numerous
research papers and tutorials are available that demonstrate the
implementation of face recognition systems using Python. These resources
cover topics ranging from data preprocessing, feature extraction, model
training, to system evaluation. The Python community actively contributes to
the field, offering code examples, libraries, and forums for knowledge sharing
and collaboration.

14
CHAPTER 3: SETTING UP ENVIRONMENT

Setting up the environment for face detection using Python and OpenCV
involves several steps to ensure the necessary tools and dependencies are
installed correctly. This section provides a detailed guide on how to set up the
environment.

a) Installing Python:
• Visit the official Python website (https://www.python.org) and
download the latest version of Python compatible with your
operating system.
• Run the installer and follow the on-screen instructions to complete
the installation process.
• Verify the Python installation by opening a terminal or command
prompt and typing "python --version" to display the installed Python
version.
b) Installing OpenCV:
• OpenCV is not included by default in Python, so it needs to be
installed separately.
• There are various methods to install OpenCV, but one common
approach is using the pip package manager.
• Open a terminal or command prompt and enter the following
command to install OpenCV using pip:
pip install opencv-python
• Wait for the installation to complete. This command installs the main
OpenCV package.
c) Installing Dependencies:

15
• While OpenCV is the main library for face detection, you may need to
install additional dependencies based on the specific requirements of
your project.
• Typically, you might need numpy for array manipulation and
matplotlib for visualizations.
• Install these dependencies by running the following commands:
pip install numpy
pip install matplotlib
• You can install other dependencies as needed for your project.

By following these steps, you will have successfully set up the environment for
face detection using Python and OpenCV.

16
CHAPTER 4: SYSTEM ARCHITECTURE

Now in this section, we will talk about the structure of our program, so as to
understand it more efficiently.

To make it simpler, we can divide the working of our system into various parts:

1. Data Collection: This component involves the acquisition of facial


images or video frames from various sources, such as cameras,
databases, or video streams. The collected data serves as the
input for subsequent stages of the face recognition pipeline.
2. Data Preprocessing: In this stage, the acquired facial data
undergoes preprocessing steps to enhance its quality and
normalize it for effective analysis. Preprocessing techniques may
include resizing, cropping, normalization etc, to ensure
consistency and improve the accuracy of subsequent processing
steps.
3. Feature Extraction: Feature extraction is a crucial step in face
recognition systems, where relevant facial features are extracted
from pre-processed images or video frames.
4. Train Face Recogniser: Train OpenCV's LBPH recogniser by feeding
it the data we prepared in step 1.
5. Face Recognition Algorithm: Once the model is trained, the face
recognition algorithm performs the identification or verification
task. It takes a query face image or video frame and compares it
against the trained model's stored representations of known
identities. The algorithm calculates similarity or distance metrics
to determine the closest match or similarity score, enabling
identification or verification of the individual.
17
CHAPTER 5: OPENCV LIBRARY

OpenCV was started at Intel in the year 1999 by Gary Bradsky. The first release
came a little later in the year 2000. OpenCV essentially stands for Open Source
Computer Vision Library. Although it is written in optimized C/ C++, it has
interfaces for Python and Java along with C++. OpenCV boasts of an active user
base all over the world with its use increasing day by day due to the surge in
computer vision applications. OpenCV-Python is the python API for OpenCV.
You can think of it as a python wrapper around the C++ implementation of
OpenCV. OpenCV-Python is not only fast (since the background consists of code
written in C/C++) but is also easy to code and deploy(due to the Python
wrapper in foreground). This makes it a great choice to perform
computationally intensive programs.

5.1 Image as arrays

An image is nothing but a standard Numpy array containing pixels of data


points. More the number of pixels in an image, the better is its resolution. You
can think of pixels to be tiny blocks of information arranged in the form of a 2 D
grid, and the depth of a pixel refers to the color information present in it. In
order to be processed by a computer, an image needs to be converted into a
binary form. Naturally, more the number of bits/pixels, more possible colours
in the images.

1. Binary Image
A binary image consists of 1 bit/pixel and so can have only two
possible
colours, i.e., black or white. Black is represented by the value 0 while
1 represents white.
18
2. Grayscale image
A grayscale image consists of 8 bits per pixel. This means it can have
256 different shades where 0 pixels will represent black color while
255 denotes white. For example, the image below shows a grayscale
image represented in the form of an array. A grayscale image has
only 1 channel where the channel represents dimension.
3. Coloured image
Coloured images are represented as a combination of Red, Blue, and
Green, and all the other colours can be achieved by mixing these
primary colours in correct proportions. A coloured image also
consists of 8 bits per pixel. As a result, 256 different shades of colours
can be represented with 0 denoting black and 255 white. Let us look
at the famous-coloured image of a mandrill which has been cited in
many image processing examples.

5.2 Classifier
Face detection is performed by using classifiers. A classifier is essentially an
algorithm that decides whether a given image is positive(face) or negative(not
a face). A classifier needs to be trained on thousands of images with and
without faces. Fortunately, OpenCV already has two pre-trained face detection
classifiers, which can readily be used in a program. The two classifiers are:

• Haar Classifier and


• Local Binary Pattern(LBP) classifier.

5.2.1 Haar Classifier


Haar-like features are digital image features used in object recognition. They
owe their name to their intuitive similarity with Haar wavelets and were used

19
in the first real-time face detector. Paul Viola and Michael Jones in their paper
titled "Rapid Object Detection using a Boosted Cascade of Simple Features"
used the idea of Haar-feature classifier based on the Haar wavelets. This
classifier is widely used for tasks like face detection in computer vision industry.
Haar cascade classifier employs a machine learning approach for visual object
detection which is capable of processing images extremely rapidly and
achieving high detection rates. This can be attributed to three main reasons:

• Haar classifier employs 'Integral Image' concept which allows the features
used by the detector to be computed very quickly.

• The learning algorithm is based on AdaBoost. It selects a small number of


important features from a large set and gives highly efficient classifiers.

• More complex classifiers are combined to form a 'cascade' which discard any
non-face regions in an image, thereby spending more computation on
promising object-like regions.

Haar Cascade is an effective method for detecting objects. It's a machine-


learning-based method in which a cascade of actions is learned from a large
number of positive and negative images. It becomes used to seeing things in
different frames. Below figure shows the view of the Haar cascade classifier
and also, Haar cascade flowchart.

20
View of Haar Cascade Classifier

Face

Feature Classifier
Training
Extraction Training

Feature Feature Strong


Extraction Selection Classifier

Haar Cascade Flowchart

21
5.2.2 LBP (Local Binary Pattern)
It is a simple but effective texture operator that labels pixels in an image by
thresholding the pixels' neighbourhood and treating the result as a binary
number. The LBP texture operator has become a common approach in a variety
of applications due to its discriminative power and computational simplicity. It
can be viewed as a unifying solution to texture analysis's historically divergent
statistical and structural models. The LBP operator's robustness to monotonic
grayscale changes induced, for example, by illumination variations is perhaps
its most significant property in real-world applications. Another key feature is
its computational simplicity, which allows it to analyse images in difficult real
time scenarios. The figure below shows the description of facial expressions
with local binary patterns.

22
CHAPTER 6: FACE DETECTION IN REAL-TIME

VIDEO STREAMS

Face detection in real-time scenarios involves processing video frames in real-


time, detecting faces, and drawing bounding boxes around them. In our project
we use the webcam of the laptop to capture images of a person, store them,
train the model based on those images and perform Face Recognition.

This section outlines the steps to implement face detection in real-time using
Python and OpenCV.

a) Accessing Video Streams:


• To perform real-time face detection, you can either utilize a webcam
or process a video file. To access the webcam feed, use the
cv2.VideoCapture() function:

cap = cv2.VideoCapture(0)

• The argument 0 represents the index of the default webcam. If you


have multiple cameras, you can use a different index accordingly.
• Alternatively, to process a video file, provide the file path as the
argument:

cap = cv2.VideoCapture('video_path.mp4')

b) Processing Video Frames:


• Create a loop to continuously read and process video frames until the
user interrupts the process:

while True: ret, frame = cap.read()

cv2.imshow('Face Detection', frame)


23
if cv2.waitKey(1) == ord('q'):

break

• The cap.read() function reads the next frame from the video stream,
and the returned values are stored in ret (a boolean indicating
success) and frame (the captured frame).
• The face detection and drawing operations will be performed on the
frame inside the loop.
• The cv2.imshow() function displays the frame in a window titled
"Face Detection".
• The loop continues until the user presses the 'q' key, triggering the
break statement.
c) Face Detection in Video Frames:
• Perform face detection on each frame using the same steps as in
the image-based face detection. Convert the frame to grayscale:
gray_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
• Apply the face detection algorithm to the grayscale frame:
faces = face_cascade.detectMultiScale(gray_frame,
scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
• Iterate over the detected faces and draw bounding boxes:
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
d) Displaying Real-Time Face Detection:
• Inside the loop, the processed frame with the bounding boxes can
be displayed using cv2.imshow().
• To ensure smooth video playback, include a small delay between
frames using cv2.waitKey():

24
cv2.imshow('Face Detection', frame)
if cv2.waitKey(1) == ord('q'):
break
• The cv2.waitKey(1) waits for 1 millisecond for a key press. If the 'q'
key is pressed, the loop breaks, and the program stops.
e) Releasing Resources:
• After exiting the loop, release the video stream and close any
open windows:
cap.release()
cv2.destroyAllWindows()

By implementing these steps, you can perform real-time face detection in video
streams using Python and OpenCV. The program continuously reads video
frames, applies face detection, draws bounding boxes around the detected
faces, and displays the processed frames in real-time. This allows for various
applications such as video surveillance, live face tracking, and real-time
analytics.

25
CHAPTER 7: CHALLENGES

Implementing face detection using Python and OpenCV can come with several
challenges. Some common challenges associated with this project include:

1. Accuracy and Robustness: Face detection algorithms may encounter


difficulties in accurately detecting faces in certain conditions, such as low
lighting, occlusions, different poses, or variations in facial expressions.
Ensuring robustness and high accuracy across different scenarios can be
a challenging task.
2. Speed and Real-Time Performance: Real-time face detection requires
processing video frames in real-time, often at high frame rates.
Achieving real-time performance while maintaining accuracy can be
challenging, especially on resource-constrained devices or when
processing high-resolution video streams.
3. False Positives and False Negatives: Face detection algorithms may
generate false positives (detecting faces where there are none) or false
negatives (failing to detect actual faces). Reducing false positives and
false negatives is crucial to ensure reliable face detection results.
4. Training Data and Model Selection: Training robust face detection
models often requires a large and diverse dataset of labeled faces.
Obtaining and preparing high-quality training data can be time-
consuming and challenging. Additionally, selecting the most suitable face
detection algorithm or model architecture for a specific application may
require experimentation and evaluation.
5. Parameter Tuning: Face detection algorithms typically have various
parameters that need to be tuned for optimal performance. Finding the
right balance between sensitivity, specificity, and computational

26
efficiency can be challenging and may require iterative adjustments and
testing.
6. Computational Resources: Face detection algorithms can be
computationally demanding, especially when applied to large images or
real-time video streams. Ensuring efficient memory usage and utilizing
available hardware resources, such as GPUs or dedicated AI chips, may
be necessary to achieve real-time performance.
7. Privacy and Ethical Considerations: Face detection involves processing
sensitive personal data. Adhering to privacy regulations, obtaining
consent, and implementing secure data handling practices are essential
to protect individuals' privacy rights and ensure ethical use of face
detection technology.
8. Scalability and Deployment: Scaling face detection solutions to handle
large-scale applications, such as video surveillance systems or real-time
monitoring, may present challenges in terms of computational
resources, network bandwidth, and system architecture. Designing
scalable and efficient deployment strategies is crucial for successful
implementation. Overcoming these challenges requires a combination of
domain knowledge, algorithmic expertise, careful parameter tuning,
data preprocessing, and thorough testing. It may also involve leveraging
advancements in deep learning, optimization techniques, and hardware
acceleration to address the computational demands of real-time face
detection applications.

27
CHAPTER 8: FUTURE SCOPE

The future scope of face recognition systems is quite promising, as this


technology continues to advance and find applications in various fields. Here
are some potential areas where face recognition systems could have a
significant impact:

1. Security and Law Enforcement: Face recognition systems are already being
used for surveillance and security purposes, such as identifying individuals in
public spaces, airports, and other high-security areas. In the future, this
technology could play a crucial role in preventing crimes, tracking suspects, and
enhancing overall public safety.

2. Access Control and Authentication: Face recognition systems have the


potential to replace traditional methods of access control and authentication,
such as keys, passwords, or swipe cards. This could be applied in various
settings, including unlocking smartphones, accessing buildings or restricted
areas, authorizing financial transactions, and more.

3. Personalized Marketing and Customer Experience: With face recognition,


businesses can analyze customer demographics and behavior, enabling
personalized marketing and improving customer experiences. For example,
retail stores can use this technology to offer tailored product
recommendations, targeted advertising, and seamless checkout processes.

4. Healthcare and Medical Applications: Face recognition systems can assist in


healthcare settings by identifying patients, tracking medication adherence,
monitoring vital signs, and enhancing patient safety. They can also be used for

28
medical research, assisting in the diagnosis of genetic disorders or identifying
early signs of certain diseases.

5. Human-Computer Interaction: Face recognition can enable more natural


and intuitive interactions between humans and computers. It can be applied in
areas such as gaming, virtual reality, augmented reality, and smart homes,
where facial expressions and gestures can control devices or provide input.

6. Personalized Education: Face recognition systems could be utilized in


educational settings to track student attendance, monitor engagement levels,
and adapt learning materials based on individual preferences and needs. This
can help create personalized learning experiences and improve educational
outcomes.

7. Travel and Transportation: Face recognition systems can enhance security


and streamline processes in travel and transportation sectors. For instance,
airports can use this technology for faster and more efficient passenger
verification, border control, and baggage tracking.

8. Public Safety and Crime Prevention: Face recognition systems can aid in
identifying and tracking criminals, reducing the occurrence of crimes, and
enhancing public safety. They can be integrated with surveillance cameras,
body-worn cameras, and other law enforcement tools to assist in
investigations.

9. Social Media and Online Presence: Face recognition can be employed by


social media platforms to automatically tag people in photos or videos,
improve content recommendation algorithms, and provide enhanced privacy
settings.

29
10. Privacy and Ethical Considerations: As face recognition technology
becomes more prevalent, it is crucial to address privacy concerns and establish
robust regulations and ethical guidelines to ensure responsible use, prevent
misuse, and protect individuals' rights.

It is important to note that the development and deployment of face


recognition systems should be done carefully, considering legal and ethical
considerations to balance security, convenience, and privacy.

30
CHAPTER 9: ETHICAL CONSIDERATIONS

The deployment of face recognition systems requires careful consideration of

ethical aspects:

a. Informed Consent: Ensuring individuals are aware of the system's

presence and purpose, and obtaining their consent when necessary.

b. Data Protection: Implementing measures to protect facial data,

including encryption, secure storage, and strict access controls.

c. Transparency and Accountability: Organizations should provide

clear information about system usage, policies, and accountability

mechanisms.

d. Bias Mitigation: Regular assessment and mitigation of bias to avoid

discrimination based on factors such as race, gender, or age.

e. Regulation and Governance: Establishing regulations and

standards for the development, deployment, and use of face

recognition systems.

31
CHAPTER 10: PROJECT IMPLEMENTATION

10.1 Project Source Code

10.1.1 Face Detection and Storing Images

import cv2

import os

cam = cv2.VideoCapture(0)

cam.set(3, 640)

cam.set(4, 480)

face_detector=cv2.CascadeClassifier(cv2.data.haarcascades+'haarcascade_fron

talface_default.xml')

while (1):

face_id = (input('\n Enter User ID ==> '))

path = './FacialDetection/dataset/User.'+face_id+'.1.jpg'

isExist = os.path.exists(path)

if isExist:

print(" User ID Already Taken")

32
else:

break

count = 0

name = input(" Enter your name: ")

with open("Details.txt", "a") as f:

f.write(f"{name}\n")

print("\n [INFO] Initializing face capture. Look the camera and wait ...")

while(True):

ret, img = cam.read()

faces = face_detector.detectMultiScale(img, 1.3, 5)

for (x,y,w,h) in faces:

cv2.rectangle(img, (x,y), (x+w,y+h), (0,255,0), 2)

count += 1

name='"./FacialDetection/dataset/User."'+face_id+'/'+ str(count) + '.jpg'

print("Creating Images........." +name)

cv2.imwrite("FacialDetection/dataset/User." + str(face_id) + '.' + str(count)

".jpg", img[y:y+h,x:x+w])

33
cv2.imshow('image', img)

k = cv2.waitKey(100) & 0xff # Press 'ESC' for exiting video

if k == 27:

break

elif count >= 200:

break

print("\n [INFO] Exiting Program and cleanup stuff")

cam.release()

cv2.destroyAllWindows()

10.1.2 Training the model

import cv2

import numpy as np

from PIL import Image

import os

path = 'FacialDetection/dataset'

recognizer = cv2.face.LBPHFaceRecognizer_create()

34
detector = cv2.CascadeClassifier(cv2.data.haarcascades

+"haarcascade_frontalface_default.xml");

def getImagesAndLabels(path):

imagePaths = [os.path.join(path,f) for f in os.listdir(path)]

faceSamples=[]

ids = []

for imagePath in imagePaths:

PIL_img = Image.open(imagePath).convert('L')

img_numpy = np.array(PIL_img,'uint8')

id = int(os.path.split(imagePath)[-1].split(".")[1])

faces = detector.detectMultiScale(img_numpy)

for (x,y,w,h) in faces:

faceSamples.append(img_numpy[y:y+h,x:x+w])

ids.append(id)

return faceSamples,ids

print ("\n [INFO] Training faces. It will take a few seconds. Wait ...")

faces,ids = getImagesAndLabels(path)

35
recognizer.train(faces, np.array(ids))

recognizer.write('FacialDetection/dataset/trainer.yml')

print("\n [INFO] {0} faces trained. Exiting Program".format(len(np.unique(ids))))

10.1.3 Face Recognition

import cv2

import numpy as np

import os

recognizer = cv2.face.LBPHFaceRecognizer_create()

recognizer.read("FacialDetection/dataset/trainer.yml")

cascadePath = cv2.data.haarcascades + "haarcascade_frontalface_default.xml"

faceCascade = cv2.CascadeClassifier(cascadePath)

font = cv2.FONT_HERSHEY_SIMPLEX

id = 0

names=['None']

content=True

i=0

with open("Details.txt", "r") as f:


36
while content:

content=f.readline()

content=content.replace('\n','')

i=i+1

names.insert(i,content)

names.pop()

cam = cv2.VideoCapture(0)

cam.set(3, 640)

cam.set(4, 480)

minW = 0.1 * cam.get(3)

minH = 0.1 * cam.get(4)

while True:

ret, img = cam.read()

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

faces = faceCascade.detectMultiScale(

gray,

scaleFactor=1.2,

37
minNeighbors=5,

minSize=(int(minW), int(minH)),

for x, y, w, h in faces:

cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)

id, confidence = recognizer.predict(gray[y : y + h, x : x + w])

if confidence < 100:

id = names[id]

confidence = " {0}%".format(round(100 - confidence))

else:

id = "unknown"

confidence = " {0}%".format(round(100 - confidence))

cv2.putText(img, str(id), (x + 5, y - 5), font, 1, (255, 255, 255), 2)

cv2.putText(img, str(confidence), (x + 5, y + h - 5), font, 1, (255, 255, 0), 1)

cv2.imshow("camera", img)

k = cv2.waitKey(10) & 0xFF

if k == 27:

38
break

print("\n [INFO] Exiting Program and cleanup stuff")

cam.release()

cv2.destroyAllWindows()

10.2 Project Output

Capturing Multiple Images

39
Detecting known face with accuracy of 49%

40
CONCLUSION

In this report, we explored the world of face detection using Python and

OpenCV. Face detection is a fundamental task in computer vision, and Python

coupled with the powerful OpenCV library provides a versatile and accessible

platform for implementing face detection algorithms.

We began by setting up the environment, ensuring Python and OpenCV were

installed correctly. Creating a virtual environment and installing necessary

dependencies were crucial steps to maintain a consistent and isolated

development environment.

Next, we delved into working with images for face detection. We covered

loading and preprocessing images, applying face detection algorithms, and

drawing bounding boxes around detected faces. These foundational steps

allowed us to understand the core principles of face detection using Python

and OpenCV.

Moving on, we explored face detection in real-time video streams. We

discussed accessing video streams from webcams or video files and processing

consecutive frames for face detection. Drawing bounding boxes around

detected faces and displaying the real-time results formed the basis for

41
applications such as surveillance, live face tracking, and interactive

experiences.

We also touched upon advanced topics such as facial recognition and

identification, face tracking, integration with other computer vision tasks,

performance optimization, and ethical considerations. These advanced topics

showcased the broader applications and potential of face detection beyond

basic detection, offering opportunities for personalized experiences, enhanced

security, and valuable insights.

Furthermore, we presented case studies/future scope across different

industries, demonstrating how face detection is utilized in real-world scenarios.

From surveillance and security to marketing and healthcare, face detection has

proven its significance in improving security measures, enhancing user

experiences, and enabling innovative solutions.

In conclusion, face detection using Python and OpenCV is a powerful tool that

unlocks numerous possibilities across various domains. Its ease of use, coupled

with its rich functionality, allows developers to build robust face detection

applications. By leveraging the concepts and techniques presented in this

42
report, practitioners can explore and create innovative solutions in fields such

as security, entertainment, marketing, healthcare, and more.

As technology advances, face detection continues to evolve, opening doors to

new applications and opportunities. By staying informed about the latest

advancements and research in face detection, practitioners can further

enhance their skills and contribute to the growth of this exciting field.

With Python and OpenCV as your tools, you are equipped to embark on your

face detection journey and make a significant impact in the world of computer

vision.

43
REFERENCES

1. https://www.electronicid.eu/en/blog/post/face-recognition/en

2. https://student.nielit.gov.in/

3. https://en.wikipedia.org/wiki/National_Institute_of_Electronics_%26_In

formation_Technology

4. https://www.geeksforgeeks.org/opencv-overview/

5. https://towardsdatascience.com/face-detection-with-haar-cascade-

727f68dafd08

6. https://www.javatpoint.com/digital-image-processing-tutorial

7. http://www.iis.fraunhofer.de/bv/biometrie/download/index.html

44

You might also like