0% found this document useful (0 votes)
160 views

Facial Recognition System

The document provides a progress report on modelling and simulation of a facial recognition system. It discusses using OpenCV for facial recognition with a webcam. It describes the three main steps: data gathering/detection by collecting face images to train the model, training the recognizer by feeding it face data and names, and then performing recognition on new faces. It focuses on using the LBP classifier for its speed, discussing how LBP extracts features from images for classification. The coding section shows loading an image, detecting faces using the LBP classifier, and printing the number of faces detected.

Uploaded by

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

Facial Recognition System

The document provides a progress report on modelling and simulation of a facial recognition system. It discusses using OpenCV for facial recognition with a webcam. It describes the three main steps: data gathering/detection by collecting face images to train the model, training the recognizer by feeding it face data and names, and then performing recognition on new faces. It focuses on using the LBP classifier for its speed, discussing how LBP extracts features from images for classification. The coding section shows loading an image, detecting faces using the LBP classifier, and printing the number of faces detected.

Uploaded by

aryaman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

MODELLING AND SIMULATION

PROGRESS REPORT
FACIAL RECOGNITION SYSTEM

BY: ARYAMAN DOSAJH(2K19/SE/018) AND CHIRAG


VERMA(2K19/SE/032)
INTRODUCTION
Machine learning is a subfield of Artificial Intelligence. The trends in advancement of AI
pertains its success to the computation capabilities of the modern day CPUs and GPUs which
can run large datasets and give us results. The smart phones of today, without an exception
have a selfie camera, which generally has a rectangular boundary around the face. The selfie
camera has certain features, like it may display the age of the person, the gender of the
person. The accuracy of the features displayed by the selfie camera depends on several
factors.

Such as light, angle, beauty mode enabled etc. The smart phone industry, uses a pre- trained
model to recognize the gender and age of the person. The pre-trained model uses deep
learning to identify features using which it predicts the gender and age of the person based on
identifying and analyzing facial features.

Problem Statement
The problem statement is to recognize the face that is feeded into the model via webcam. The
image will be feeded to the pre-trained model via a webcam. This venture was finished with
this incredible "Open Source Computer Vision Library", the OpenCV. OpenCV was intended
for computational proficiency and with a solid spotlight on continuous applications. In this
way, it's ideal for ongoing face acknowledgment utilizing a camera.
Overview of the classifier

Use of OpenCV face recognizers

Thanks to OpenCV, coding facial recognition is now easier than ever. There
are three easy steps to computer coding facial recognition, which are similar
to the steps that our brains use for recognizing faces. These steps are:

 Data Gathering/Detection: Gather face data (face images in this case)


of the persons you want to identify.
 Train the Recognizer: Feed that face data and respective names of
each face to the recognizer so that it can learn.
 Recognition: Feed new faces of that people and see if the face
recognizer you just trained recognizes them.
It's that simple!

NEED OF CASCADE CLASSIFIER


• In an image, most of the image is non-face region. So it is a better idea to have
a simple method to check if a window is not a face region. If it is not, discard it
in a single shot, and don't process it again. Instead, focus on regions where
there can be a face. This way, we spend more time checking possible face
regions.

• For this they introduced the concept of Cascade of Classifiers.

• OpenCV provides a training method or pretrained models, that can be read


using the cv::CascadeClassifier::load method. The pretrained models are
located in the data folder in the OpenCV installation.

• OpenCV provides us with a class cv2.CascadeClassifier which takes as input


the training file of the (Haar/LBP) classifier we want to load and loads it for us.

Theory or face detection classifiers

A computer program that decides whether an image is a positive image (face


image) or negative image (non-face image) is called a classifier. A classifier is
trained on hundreds of thousands of face and non-face images to learn how to
classify a new image correctly. OpenCV provides us with two pre-trained and
ready to be used for face detection classifiers:

1. Haar Classifier
2. LBP Classifier

Both of these classifiers process images in gray scales, basically because we


don't need color information to decide if a picture has a face or not . As these
are pre-trained in OpenCV, their learned knowledge files also come bundled
with OpenCV opencv/data/.

To run a classifier, we need to load the knowledge files first, as if it had no


knowledge, just like a newly born baby (stupid babies).
Each file starts with the name of the classifier it belongs to. For example,
a Haar cascade classifier starts off as haarcascade_frontalface_alt.xml.

Each OpenCV face detection classifier has its pros and cons, but the major
differences are in accuracy and speed.

So, in case more accurate detections are required, Haar classifier is the way
to go. This bad boy is more suitable in technology such as security systems or
high-end stalking.

But the LBP classifier is faster, therefore, should be used in mobile


applications or embedded systems.
“THEREFORE, WE WILL CONTINUE WITH LPB”

LBP Cascade Classifier

As any other classifier, the Local Binary Patterns, or LBP in short, also needs
to be trained on hundreds of images. LBP is a visual/texture descriptor, and
thankfully, our faces are also composed of micro visual patterns.

So, LBP features are extracted to form a feature vector that classifies a face
from a non-face.

Each training image is divided into some blocks as shown in the picture below.

LBP Windows (disregard the first grader drawing)

For each block, LBP looks at 9 pixels  (3×3 window) at a time, and with a
particular interest in the pixel located in the center of the window.

Then, it compares the central pixel value with every neighbor's pixel value
under the 3×3 window. For each neighbor pixel that is greater than or equal to
the center pixel, it sets its value to 1, and for the others, it sets them to 0.

After that, it reads the updated pixel values (which can be either 0 or 1) in a
clockwise order and forms a binary number. Next, it converts the binary
number into a decimal number, and that decimal number is the new value of
the center pixel. We do this for every pixel in a block.

LBP conversion to binary. Local Binary Patterns applied to Face Detection


and Recognition.

Now, after you get a list of local binary patterns, you convert each one into a
decimal number using binary to decimal conversion  (as shown in above
image) and then you make a histogram of all of those decimal values. A
sample histogram looks like this:

Histogram Sample.

And this is how our Face Detector will look once we finish coding it:
Coding Face Recognition using Python and OpenCV

We are going to divide the Face Recognition process into three steps:

1. Prepare Training Data: 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.
2. Train Face Recognizer: Train OpenCV's LBPH recognizer by feeding it
the data we prepared in step 1.
3. Prediction: Introduce some test images to face recognizer and see if it
predicts them correctly.

CODE:
Let's start with a simple task, load our input image, convert it  to grayscale
mode and then display it.

For this, we’ll need to keep at arms reach this very handy
function cv2.cvtColor (converting images to grayscale).

This step is necessary because many operations in OpenCV are done in


grayscale for performance reasons.

To read/load our image and convert it to grayscale, I used OpenCV’s built in


function cv2.imread(img_path) and passed our image path as the input parameter.

#load test iamge


test1 = cv2.imread('data/test1.jpg')
#convert the test image to gray image as opencv face detector expects gray images
gray_img = cv2.cvtColor(test1, cv2.COLOR_BGR2GRAY)
To display our image, I’ll use the plt.imshow(img, cmap) function of matplotlib.

#if you have matplotlib installed then


plt.imshow(gray_img, cmap='gray')

# or display the gray image using OpenCV


# cv2.imshow('Test Imag', gray_img)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

Before we can continue with face detection, we have to load our LBP cascade
classifier.

#load cascade classifier training file for lbpcascade 


lbp_face_cascade =
cv2.CascadeClassifier('data/lbpcascade_frontalface.xml')  

#load test image


test2 = cv2.imread('data/test2.jpg')
#call our function to detect faces
faces_detected_img = detect_faces(lbp_face_cascade, test2)
#convert image to RGB and show image
plt.imshow(convertToRGB(faces_detected_img))

Now, how do we detect a face from an image using the Cascade


Classifier we just loaded?

Well, again OpenCV's Cascaded Classifier has made it simple for us as it


comes with the function detectMultiScale, which detects exactly that. Next are
some details of its options/arguments:

 detectMultiScale(image, scaleFactor, minNeighbors):  This is a general


function to detect objects, in this case, it'll detect faces since we called
in the face cascade. If it finds a face, it returns a list of positions of said
face in the form “Rect(x,y,w,h).”, if not, then returns “None”.
 Image: The first input is the grayscale image. So make sure the image
is in grayscale.
 scaleFactor: This function compensates a false perception in size that
occurs when one face appears to be bigger than the other simply
because it is closer to the camera.
 minNeighbors: This is a detection algorithm that uses a moving
window to detect objects, it does so by defining how many objects are
found near the current one before it can declare the face found.

There are other parameters as well. These parameters need to be tuned


according to your own data.

Now that we know a straightforward way to detect faces, we could now find
the face in our test image .

Then, let's find one!

The following code will try to detect a face from the image and, if detected, it
will print the number of faces that it has found, which in our case should be 1.

#let's detect multiscale (some images may be closer to camera than others) images
faces = lpb_face_cascade.detectMultiScale(gray_img, scaleFactor=1.1, minNeighbors=5);

#print the number of faces found


print('Faces found: ', len(faces))

Faces found: 1

Next, let's loop over the list of faces (rectangles) it returned and drew those
rectangles using yet another built-in OpenCV rectangle function on our
original colored image to see if it found the right faces:

#go over list of faces and draw them as rectangles on original colored
img for (x, y, w, h) in faces:
    cv2.rectangle(test1, (x, y), (x+w, y+h), (0, 255, 0), 2)

Let’s display the original image to see the rectangles we just drew and verify
that detected faces are real ones and not any false positives.

#convert image to RGB and show image


plt.imshow(convertToRGB(test1))
AFTER THIS COMES THE RECOGNITION PROCESS WHICH WILL BE
DONE FURTHER AHEAD.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy