Face Filter Using OpenCV

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 21

AJAY KUMAR GARG ENGINEERING COLLEGE

27th KM STONE, DELHI-HAPUR BYPASS ROAD, P.O. ADHYATMIK NAGAR


GHAZIABAD-201009

AN

INDUSTRIAL TRAINING REPORT

ON

FACE RECOGNITION SYSTEM

AT

AKATVA (TCS TRAINING PARTNER), NOIDA

Submitted by Under the Guidance of


Name : ARSALAAN ALI
Roll No. : 1602710801 Mr. AMAN CHAUDHARY
Year : IV
Semester : VII
Section : CS-1
Branch : CSE
Date : 30/07/2018

1
TRAINING CERTIFICATE

This is to certify that ARSALAAN ALI, student of AJAY KUMAR GARG

ENGINEERING COLLEGE B.Tech Final year CSE branch, has undergone

Industrial Training in Face Filter System (Based on Machine learning with python)

from June 8, 2018 to July 20, 2018.

Dr. Sunita Yadav Gp Capt. (Dr.) PK Chopra (Retd.) VSM


Prof. & HoD (CSE) Prof. & HoD (T&P)

2
ACKNOWLEDGEMENT

The effort that I have put in my report would not have been possible without the support and help
of many individuals. I would like to extend my sincere thanks to all of them.
I extend my gratitude to Dr. Sunita Yadav, HoD CSE for providing with excellent infrastructure
and awesome environment that laid potentially strong foundation for my professional life.
I would like to especially thank Ms. Shiva Tyagi and Ms. Aarti Mishra for being a source of
support, advice and guidance in documentation and standardization of training report.
I would like to thank T&P Department for supporting us and providing valuable guidance in
selection of best options for industrial training.
I would also like to thank Mr. Aman Chaudhary, Trainer (Python and ML), Akatva (TCS
TRAINING PARTNER) for the positive attitude he showed towards my work, and his valuable
help and guidance which supported me during my project.

ARSALAAN ALI
1602710801

3
TABLE OF CONTENTS

CONTENT PAGE NO.

Training Certificate (College) 1

Training Certificate (Company 2

Acknowledgement 3

Table of Contents 4

List of figures 5

Chapter 1: Company Profile 6

Chapter 2: Introduction 7

Chapter 3: Project Analysis 9

Chapter 4: Snapshots and Working 14

Chapter 5: Limitations and future enhancements 18

Chapter 6: Conclusion 19

Chapter 7: References 20

4
LIST OF FIGURES

FIG. NO. DESCRIPTION PAGE NO.


Figure. 3.1: Principle Components by EigenFaces Face Recognizer 10

Figure. 3.2: Fisher Faces 11

Figure. 3.3: LBP Labelling 12

Figure. 3.4: Sample Histogram 12

Figure. 3.5: LBP Faces 13

Figure. 4.1: Training and Label subfolders 14

Figure. 4.2: Images in S1 subfolder 15

Figure. 4.3: Images in S2 subfolder 15

Figure. 4.4: Testing Images 15

Figure. 4.5: Output 17

5
CHAPTER 1
COMPANY PROFILE

Akatva is a TCS iON Training Partner focused on providing high-end and high quality
trainings on cutting-edge technologies like Java, Python, Bigdata & Hadoop, MySQL,
Microsof.NET, PHP, Android and many more to the students who come to us.
Our principals TCS iON with its vast experience and expertise in digital and other technologies
areas on a global scale provide the pedagogy and curricula of all the courses that are run in our
Training Centre. These trainings are delivered under the strict quality supervision of TCS iON
by the “TCS iON Certified” faculty with the necessary technical infrastructure of par excellence
for providing best trainings to the students.

The propellers of Akatva are educationists and academicians who nourish genuine desire in their
hearts to uplift their students in every possible manner. They focus on employability of the
students through quality trainings to make them stand on their feet in life. Aktva TCS iON is the
outcome of this desire to provide best training in the IT and digital sphere. It is the best training
hub existing today in Noida.

For helping its trained students, Akatva has a full-fledged Placement Division that takes care of
all the training needs on the soft side of the candidates before they face interviews by the
recruiters.

Akatva, TCS ION Training Partner has the following offerings:

Software Development training: For both fresher’s as well as for those who seek advanced level
training. The focus is to make the trainees employable on a variety of cutting edge technologies.

Instructor led campus: We are “Instructor-led campus” meaning hand holding of the students for
optimum output.

Workshops and Placement Service: Akatva has central placement department that focuses on
providing 100 Percent placement assistance to all students. It conducts tailor-made workshops that
enhance knowledge, competency, efficiency and employment.

6
CHAPTER 2
INTRODUCTION

A face recognition system is a computer application for automatically identifying or verifying a


person from a digital image or a video frame from a video source. One of the ways to do this is by
comparing selected facial features from the image and a facial database. It is typically used in
security systems and can be compared to other biometrics such as fingerprint or eye iris
recognition systems. Some facial recognition algorithms identify facial features by extracting
landmarks, or features, from an image of the subject's face. For example, an algorithm may analyze
the relative position, size, and/or shape of the eyes, nose, cheekbones, and jaw. These features are
then used to search for other images with matching features. Other algorithms normalize a gallery
of face images and then compress the face data, only saving the data in the image that is useful for
face recognition. A probe image is then compared with the face data. One of the earliest successful
systems is based on template matching techniques applied to a set of salient facial features,
providing a sort of compressed face representation. Recognition algorithms can be divided into
two main approaches, geometric, which looks at distinguishing features, or photometric, which is a
statistical approach that distills an image into values and compares the values with templates to
eliminate variances.

Face recognition is an easy task for humans. Experiments have shown, that even one to three day
old babies are able to distinguish between known faces. So how hard could it be for a computer? It
turns out we know little about human recognition to date. Are inner features (eyes, nose, mouth) or
outer features (head shape, hairline) used for a successful face recognition? How do we analyze an
image and how does the brain encode it? It was shown by David Hubel and Torsten Wiesel, that
our brain has specialized 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. Automatic face
recognition is all about extracting those meaningful features from an image, putting them into a
useful representation and performing some kind of classification on them.

A facial recognition system is a technology capable of identifying or verifying a person from


a digital image or a video frame from a video source. There are multiple methods in which facial
recognition systems work, but in general, they work by comparing selected features from given
image with faces within a database.
While initially a form of computer application, it has seen wider uses in recent times on mobile
platforms and in other forms of technology, such as robotics.

Face recognition based on the geometric features of a face is probably the most intuitive approach
to face recognition. One of the first automated face recognition systems was described by marker
points (position of eyes, ears, nose ...) were used to build a feature vector (distance between the

7
points, angle between them ...). The recognition was performed by calculating the Euclidean
distance between feature vectors of a probe and reference image. Such a method is robust against
changes in illumination by its nature, but has a huge drawback: the accurate registration of the
marker points is complicated, even with state of the art algorithms. A 22-dimensional feature
vector was used and experiments on large datasets have shown, that geometrical features alone my
not carry enough information for face recognition.

OpenCV (Open Source Computer Vision Library) is released under a BSD license and hence it’s
free for both academic and commercial use. It has C++, Python and Java interfaces and supports
Windows, Linux, Mac OS, iOS and Android. OpenCV was designed for computational efficiency
and with a strong focus on real-time applications. Written in optimized C/C++, the library can take
advantage of multi-core processing. Enabled with OpenCL, it can take advantage of the hardware
acceleration of the underlying heterogeneous compute platform.

Adopted all around the world, OpenCV has more than 47 thousand people of user community and
estimated number of downloads exceeding 14 million. Usage ranges from interactive art, to mines
inspection, stitching maps on the web or through advanced robotics.

The currently available algorithms are:

Eigenfaces (see createEigenFaceRecognizer())

Fisherfaces (see createFisherFaceRecognizer())

Local Binary Patterns Histograms (see createLBPHFaceRecognizer())

SCOPE OF APPLICATION

 Retail

Large retailers are using facial recognition to instantly recognize customers and present
offers. They can also use it to catch shoplifters augmented with camera footage. The
entertainment industry, casinos, and theme parks have also caught on to its uses.
Companies like NTechLab, Kairosuse face recognition technology to provide customer
analytics.

 Banking 

 Bankers are now looking to introduce face recognition in mobile apps and ATMs for
identification. China is already seeing an application where a customer withdrawing money
from ATMs in Macau need to punch in their PIN and also to stare into a camera for six
seconds so facial-recognition software can verify their identity and help monitor
transactions.
8
 Social Media

Social media platforms have adopted facial recognition capabilities to diversify their
functionalities in order to attract a wider user base amidst stiff competition from different
applications.

 Face Id

Apple introduced Face ID on the flagship iPhone X as a biometric authentication successor


to the Touch ID, a fingerprint based system. The system will not work with eyes closed, in
an effort to prevent unauthorized access. The technology learns from changes in a user's
appearance, and therefore works with hats, scarves, glasses and many sunglasses, beard and
makeup.

 Deployment in security services

1. Policing

The Australian Border Force and New Zealand Customs Services have set up an
automated border processing system called SmartGate that uses face recognition, which
compares the face of the traveller with the data in the e-passport microchip.

2. National Security

In 2017, Time & Attendance company ClockedIn released facial recognition as a form
of attendance tracking for businesses and organisations looking to have a more
automated system of keeping track of hours worked as well as for security and health
and safety control.

9
CHAPTER 3
PROJECT ANALYSIS

A general statement of the face recognition problem (in computer vision) can be formulated as
follows: given still or video images of a scene, identify or verify one or more persons in the scene
using a stored database of faces. Facial recognition generally involves two stages:

Face Detection where a photo is searched to find a face, then the image is processed to crop and
extract the person’s face for easier recognition.

Face Recognition where that detected and processed face is compared to a database of known
faces, to decide who that person is. Since 2002, face detection can be performed fairly easily and
reliably with Intel’s open source framework called OpenCV. This framework has an inbuilt Face
Detector that works in roughly 90-95% of clear photos of a person looking forward at the camera.
However, detecting a person’s face when that person is viewed from an angle is usually harder,
sometimes requiring 3D Head Pose Estimation. Also, lack of proper brightness of an image can
greatly increase the difficulty of detecting a face, or increased contrast in shadows on the face, or
maybe the picture is blurry, or the person is wearing glasses, etc.
Face recognition however is much less reliable than face detection, with an accuracy of 30-70% in
general. Face recognition has been a strong field of research since the 1990s, but is still a
far way away from a reliable method of user authentication. More and more techniques are being
developed each year. The Eigenface technique is considered the simplest method of accurate face
recognition, but many other (much more complicated) methods or combinations of multiple
methods are slightly more accurate.

OpenCV Face Recognizers


OpenCV has three built in face recognizers and thanks to OpenCV's clean coding, we can use any
of them by just changing a single line of code. Below are the names of those face recognizers and
their OpenCV calls.
 EigenFaces Face Recognizer Recognizer - cv2.face.createEigenFaceRecognizer()
 FisherFaces Face Recognizer Recognizer - cv2.face.createFisherFaceRecognizer()
 Local Binary Patterns Histograms (LBPH) Face Recognizer -
cv2.face.createLBPHFaceRecognizer()

EigenFaces Face Recognizer


This algorithm considers the fact that not all parts of a face are equally important and equally
useful. When you look at someone you recognize him/her by his distinct features like eyes, nose,
cheeks, forehead and how they vary with respect to each other. So you are actually focusing on the
areas of maximum change (mathematically speaking, this change is variance) of the face. For
example, from eyes to nose there is a significant change and same is the case from nose to mouth.
10
When you look at multiple faces you compare them by looking at these parts of the faces because
these parts are the most useful and important components of a face. Important because they catch
the maximum change among faces, change the helps you differentiate one face from the other.
This is exactly how EigenFaces face recognizer works.

EigenFaces face recognizer looks at all the training images of all the persons as a whole and try to
extract the components which are important and useful (the components that catch the maximum
variance/change) and discards the rest of the components. This way it not only extracts the
important components from the training data but also saves memory by discarding the less
important components. These important components it extracts are called principal components.
Below is an image showing the principal components extracted from a list of faces.

Fig 3.1: Principle Components by EigenFaces Face Recognizer

So this is how EigenFaces face recognizer trains itself (by extracting principal components).
Remember, it also keeps a record of which principal component belongs to which person. One
thing to note in above image is that Eigenfaces algorithm also considers illumination as an
important component.

11
FisherFaces Face Recognizer
This algorithm is an improved version of EigenFaces face recognizer. Eigenfaces face recognizer
looks at all the training faces of all the persons at once and finds principal components from all of
them combined. By capturing principal components from all the of them combined you are not
focusing on the features that discriminate one person from the other but the features that represent
all the persons in the training data as a whole.

This approach has drawbacks, for example, images with sharp changes (like light changes which is
not a useful feature at all) may dominate the rest of the images and you may end up with features
that are from external source like light and are not useful for discrimination at all. In the end, your
principal components will represent light changes and not the actual face features.

Fisherfaces algorithm, instead of extracting useful features that represent all the faces of all the
persons, it extracts useful features that discriminate one person from the others. This way features
of one person do not dominate over the others and you have the features that discriminate one
person from the others.
Below is an image of features extracted using Fisherfaces algorithm.

Fig 3.2. FisherFaces


12
It can be seen that features extracted actually represent faces and these faces are called fisher faces
and hence the name of the algorithm.

One thing to note here is that even in Fisherfaces algorithm if multiple persons have images with
sharp changes due to external sources like light they will dominate over other features and affect
recognition accuracy.

Local Binary Patterns Histograms (LBPH) Face Recognizer

First of all, we need to define the parameters (radius, neighbors, grid x and grid y) using
the Parameters structure from the lbph package. Then we need to call the Init function passing the
structure with the parameters. If we not set the parameters, it will use the default parameters as
explained in the Parameters section.

Secondly, we need to train the algorithm. To do that we just need to call the Train function passing
a slice of images and a slice of labels by parameter. All images must have the same size. The labels
are used as IDs for the images, so if you have more than one image of the same texture/subject, the
labels should be the same.

The Train function will first check if all images have the same size. If at least one image has not
the same size, the Train function will return an error and the algorithm will not be trained.

Then, the Train function will apply the basic LBP operation by changing each pixel based on its
neighbors using a default radius defined by the user. The basic LBP operation can be seen in the
following image (using 8 neighbors and radius equal to 1):

Fig 3.3. LBP Labelling

After applying the LBP operation we extract the histograms of each image based on the number of
grids (X and Y) passed by parameter. After extracting the histogram of each region, we
concatenate all histograms and create a new one which will be used to represent the image.
13
Fig 3.4. Sample Histogram

The images, labels, and histograms are stored in a data structure so we can compare all of it to
a new image in the Predict function.

Now, the algorithm is already trained and we can Predict a new image.

To predict a new image we just need to call the Predict function passing the image as
parameter. The Predict function will extract the histogram from the new image, compare it to
the histograms stored in the data structure and return the label and distance corresponding to
the closest histogram if no error has occurred. Note: It uses the distance metric as the default
metric to compare the histograms. The closer to zero is the distance, the greater is the
confidence.

Fig 3.5. LBP Faces

14
CHAPTER 4
SNAPSHOTS AND WORKING

The Face Recognition process is divided into three steps.


1. Prepare training data: In this step we will read training images for each person/subject along
with their labels, detect faces from each image and assign each detected face an integer label of the
person it belongs to.
2. Train Face Recognizer: In this step we will train OpenCV's LBPH face recognizer by feeding it
the data we prepared in step 1.
3. Testing: In this step we will pass some test images to face recognizer and see if it predicts them
correctly.
Training Data
The more images used in training the better. Normally a lot of images are used for training a face
recognizer so that it can learn different looks of the same person, for example with glasses, without
glasses, laughing, sad, happy, crying, with beard, without beard etc. To keep our tutorial simple we
are going to use only 20 images for each person.
So our training data consists of total 2 persons with 20 images of each person. All training data is
inside _`training-data`_ folder. _`training-data`_ folder contains one folder for each person and
each folder is named with format `sLabel (e.g. s1, s2)` where label is actually the integer label
assigned to that person. For example folder named s1 means that this folder contains images for
person 1. The directory structure tree for training data is as follows:

15
Fig 4.1 Training and label subfolders

Fig 4.2 Images in S1 subfolder

Fig 4.3 Images in S2 subfolder

The _`test-data`_ folder contains images that we will use to test our face recognizer after it has
been successfully trained.

Fig 4.4 Testing Images

As OpenCV face recognizer accepts labels as integers so we need to define a mapping between
integer labels and persons actual names so below defining a mapping of persons integer labels and
their respective names.

16
Prepare training data
Well, OpenCV face recognizer accepts data in a specific format. It accepts two vectors, one vector
is of faces of all the persons and the second vector is of integer labels for each face so that when
processing a face the face recognizer knows which person that particular face belongs too.
For example, if we had 2 persons and 2 images for each person.
PERSON-1 PERSON-2

img1 img1
img2 img2

Then the prepare data step will produce following face and label vectors.
FACES LABELS

person1_img1_face 1
person1_img2_face 1
person2_img1_face 2
person2_img2_face 2

Testing
Now our data is prepared and we will now use any of the three face recognizers. Here using LBPH
recognizer, we are ready to predict the test images and generate the output.

17
Output:

Fig 4.5 Output

18
CHAPTER 5
LIMITATIONS AND FUTURE ENHANCEMENTS

Some of the limitations in the project are listed below:


 Accuracy is less since a set of few images is used.
 Not integrated with any real time application.
 Hyper Parameter tuning required to increase the chance of correct prediction.
 A simple face filter which can only detect faces.

Further enhancements could be:


 Can be integrated with some real time android apps.
 A large set of images can be used to increase the accuracy.
 A generalized recognizer system can be build which can also detect other images besides
human faces.
 Deep learning (Convolution Neural Network) can be used for fast image recognition.

19
CHAPTER 6
CONCLUSION

The subject of visual processing of human faces has received attention from philosophers and
scientists for centuries. Generally, feature extraction, discriminant analysis and classifying
criterion are the three basic elements of a face recognition system. The performance and robustness
of face recognition could be enhanced by improving these elements. Feature extraction in the sense
of some linear or nonlinear transform of the data with subsequent feature selection is commonly
used for reducing the dimensionality of facial image so that the extracted features are as
representative as possible. This thesis study mainly focuses on use of multiresolution,
multidirectional transforms and independent component analysis (ICA) in face recognition.

Though still in its primal stage a face filter system can be used to detect multiple faces either live
using web cam or by giving a set of images. It will show your name on your image to give you a
real time experience how a face is detected using face ids on mobile phones and other systems.

On a personal and a moral front I have understood that one should always enjoy the work he is
doing and only then one can actually be successful, another lesson is that no matter how senior an
employee you are there will always be someone who needs your guidance and help, and also
consequently there will always be someone from whom you can learn and gain something, so
never be shy or egoistic in doing so.

Overall, the industrial training proved to be helpful in enhancing the trainee’s practical skills, and a
wonderful stimulus for extension of theoretical knowledge to real world applications.

20
CHAPTER 7
REFERENCES

Various web resource proved to be vital for successful completion of the training project. Some of
them are mentioned here

1. https://www.wikipedia.com
2. https://www.opencv.org
3. https://www.icml.cc/
4. https://www.pythonprogramming.net
5. https://www.superdatascience.com
6. https://www.elitedatascience.com
7. https://www.stackoverflow.com

21

You might also like