Industrial Report
Industrial Report
SESSION: 2020-24
SUBMITTED TO SUBMITTED BY
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.
1
CERTIFICATE
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
CHAPTER 7: CHALLENGES…………………………………………………………26-27
5
CHAPTER 9: ETHICAL CONSIDERATIONS………………………………………….31
CONCLUSION……………………………………………………………………………...41-43
REFERENCES…………………………………………………………………………………44
6
ABOUT ORGANIZATION-NIELIT
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.
8
EXPERIENCE
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.
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.
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.
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:
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.
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:
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.
• 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.
20
View of Haar Cascade Classifier
Face
Feature Classifier
Training
Extraction Training
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
This section outlines the steps to implement face detection in real-time using
Python and OpenCV.
cap = cv2.VideoCapture(0)
cap = cv2.VideoCapture('video_path.mp4')
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:
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
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.
28
medical research, assisting in the diagnosis of genetic disorders or identifying
early signs of certain diseases.
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.
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.
30
CHAPTER 9: ETHICAL CONSIDERATIONS
ethical aspects:
mechanisms.
recognition systems.
31
CHAPTER 10: PROJECT IMPLEMENTATION
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):
path = './FacialDetection/dataset/User.'+face_id+'.1.jpg'
isExist = os.path.exists(path)
if isExist:
32
else:
break
count = 0
f.write(f"{name}\n")
print("\n [INFO] Initializing face capture. Look the camera and wait ...")
while(True):
count += 1
".jpg", img[y:y+h,x:x+w])
33
cv2.imshow('image', img)
if k == 27:
break
break
cam.release()
cv2.destroyAllWindows()
import cv2
import numpy as np
import os
path = 'FacialDetection/dataset'
recognizer = cv2.face.LBPHFaceRecognizer_create()
34
detector = cv2.CascadeClassifier(cv2.data.haarcascades
+"haarcascade_frontalface_default.xml");
def getImagesAndLabels(path):
faceSamples=[]
ids = []
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)
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')
import cv2
import numpy as np
import os
recognizer = cv2.face.LBPHFaceRecognizer_create()
recognizer.read("FacialDetection/dataset/trainer.yml")
faceCascade = cv2.CascadeClassifier(cascadePath)
font = cv2.FONT_HERSHEY_SIMPLEX
id = 0
names=['None']
content=True
i=0
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)
while True:
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.2,
37
minNeighbors=5,
minSize=(int(minW), int(minH)),
for x, y, w, h in faces:
id = names[id]
else:
id = "unknown"
cv2.imshow("camera", img)
if k == 27:
38
break
cam.release()
cv2.destroyAllWindows()
39
Detecting known face with accuracy of 49%
40
CONCLUSION
In this report, we explored the world of face detection using Python and
coupled with the powerful OpenCV library provides a versatile and accessible
development environment.
Next, we delved into working with images for face detection. We covered
and OpenCV.
discussed accessing video streams from webcams or video files and processing
detected faces and displaying the real-time results formed the basis for
41
applications such as surveillance, live face tracking, and interactive
experiences.
From surveillance and security to marketing and healthcare, face detection has
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
42
report, practitioners can explore and create innovative solutions in fields such
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