Professional Documents
Culture Documents
on:
Face Detection using Open CV Machine
Learning
By
Diba Sayed
Mohibullah Amiri Eng. Majid Niazi
1
Table of contents
Abstract ............................................................................................................................................. 3
1. Introduction ............................................................................................................................... 3
FACE RECOGNIZATION: .......................................................................................................... 3
DIFFERENT APPROACHES OF FACE RECOGNITION: ................................................... 3
1.2 FACE DETECTION: .............................................................................................................. 4
2. Problem Statement ........................................................................................................................ 4
3. Proposed System ........................................................................................................................... 4
4. Project Design ............................................................................................................................... 5
5. Tools used ..................................................................................................................................... 7
Deep learning ................................................................................................................................ 8
What Is Deep Learning? ........................................................................................................... 8
How Deep Learning Works ...................................................................................................... 9
How our algorithm works ............................................................................................................... 10
Module for face detection ............................................................................................................. 11
Conclusion ...................................................................................................................................... 13
Future Enhancement ....................................................................................................................... 13
References ....................................................................................................................................... 14
2
Abstract
dentifying a person with an image has been popularised through the mass media.
However,it is less robust to fingerprint or retina scanning. This report describes the
face detection and recognition mini-project undertaken for the visual perception and
autonomy module at Plymouth university. It reports the technologies available in the
Open-Computer-Vision (OpenCV) library and methodology to implement them
using Python. For face detection, Haar-Cascades were used and for face recognition
Eigenfaces, Fisherfaces and Local binary pattern histograms were used. The
methodology is described including flow charts for each stage of the system. Next,
the results are shown including plots and screen-shots followed by a discussion of
encountered challenges.
1. Introduction
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 this input face.
FACE RECOGNIZATION:
DIFFERENT APPROACHES OF FACE RECOGNITION:
There are two predominant approaches to the face recognition problem: Geometric
(Feature based) and photometric (view based). As researcher interest in face
recognition continued, many different algorithms were developed, three of which
have been well studied in face recognition literature.
3
then faces are classified on the basis of various geometrical distances and angles
between features.
2. Photometric stereo: Used to recover the shape of an object from a number of mages
taken under different lighting conditions. The shape of the recovered object is defined
by a gradient map.
4
classification task that takes some arbitrary image as input and outputs a binary
value of yes or no, indicating whether there are any faces present in the image. The
second step is the face localization task that aims to take an image as input and
output the location of any face or faces within that image as some bounding box
with (x, y, width, height).
The face detection system can be divided into the following steps: -
1. Pre-Processing: To reduce the variability in the faces, the images are processed
before they are fed into the network. All positive examples that is the face images
are obtained by cropping images with frontal faces to include only the front view.
All the cropped images are then corrected for lighting through standard algorithms.
2. Classification: Neural networks are implemented to classify the images as faces
or nonfaces by training on these examples. We use both our implementation of the
neural network and the Matlab neural network toolbox for this task. Different
network configurations are experimented with to optimize the results.
3. Localization: The trained neural network is then used to search for faces in an
image and if present localize them in a bounding box.
4. Project Design
The model we used is built with Keras using Convolutional Neural Networks
(CNN). A convolutional neural network is a special type of deep neural network
which performs extremely well for image classification purposes. A CNN basically
consists of an input layer, an output layer and a hidden layer which can have multiple
numbers of layers. A convolution operation is performed on these layers using a
filter that performs 2D matrix multiplication on the layer and filter.
The CNN model architecture consists of the following layers:
6
To teach an algorithm how to recognise objects in images, we use a specific type of
Artificial Neural Network: a Convolutional Neural Network (CNN). Their name
stems from one of the most important operations in the network: convolution.
Convolutional Neural Networks are inspired by the brain. Research in the 1950s and
1960s by D.H Hubel and T.N Wiesel on the brain of mammals suggested a new
model for how mammals perceive the world visually. They showed that cat and
monkey visual cortexes include neurons that exclusively respond to neurons in their
direct environment.
5. Tools used
In this Python project, we will be using OpenCV for gathering the images from
webcam and feed them into a Deep Learning model which will classify whether the
person’s eyes are ‘Open’ or ‘Closed’. the requirement for this Python project is a
webcam through which we will capture images. You need to have Python (3.6
7
version recommended) installed on your system, then using pip, you can install the
necessary packages.
Step 2 – Detect the face in the image and create a Region of Interest (ROI).
Step 3 – Detect the eyes from ROI and feed it to the classifier.
Deep learning
For the purpose of working with algorithms of AI we need brief knowledge in deep learning which
will make easy the things for making projects and solving the real case problems which will helpful
for the humanity and will be a way for new technologies to come out.
8
unsupervised from data that is unstructured or unlabeled. Also known as deep
neural learning or deep neural network.
• Deep learning is an AI function that mimics the workings of the human brain
in processing data for use in detecting objects, recognizing speech, translating
languages, and making decisions.
• Deep learning AI is able to learn without human supervision, drawing from
data that is both unstructured and unlabeled.
• Deep learning, a form of machine learning, can be used to help detect fraud or
money laundering, among other functions.
However, the data, which normally is unstructured, is so vast that it could take
decades for humans to comprehend it and extract relevant information. Companies
realize the incredible potential that can result from unraveling this wealth of
information and are increasingly adapting to AI systems for automated support.
Camera
In this project we need a camera to take pictures when we run our code. The camera
will capture multiple photos and will detect the eyes is it open or close.
Operating system
9
It is an open-source project. We can run the code of this project in any operating
system. But we used windows 10, 64-bit operating system and x64-based processer.
Step 3 – Detect the eyes from ROI and feed it to the classifier
The same procedure to detect faces is used to detect eyes. First, we set the cascade
classifier for eyes in leye and reye respectively then detect the eyes using left_eye =
leye.detectMultiScale(gray). Now we need to extract only the eyes data from the full
10
image. This can be achieved by extracting the boundary box of the eye and then we
can pull out the eye image from the frame with this code.
l_eye only contains the image data of the eye. This will be fed into our CNN classifier
which will predict if eyes are open or closed. Similarly, we will be extracting the
right eye into r_eye.
gray = cv2.cvtColor(img,
cv2.COLOR_BGR2GRAY) faces =
face_cascade.detectMultiScale(gray, 1.1, 4)
11
for (x, y, w, h) in faces: cv2.rectangle(img,
(x, y), (x+w, y+h), (255, 0, 0), 3)
cv2.imshow('img', img) if cv2.waitKey(1) &
0xFF == ord('q'): break cap.release()
photo capturing of the region of interest
import cv2
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
12
Conclusion
But face recognition data can be prone to error, which can implicate people for
crimes they haven’t committed. Facial recognition software is particularly bad at
recognizing African Americans and other ethnic minorities, women, and young
people, often misidentifying or failing to identify them, disparately impacting
certain groups.
Future Enhancement
Future Enhancement Assistance has an immensely boundless scope in future. It can
be amended as and when requirement emerges, as it is versatile in terms of the
13
extension. There are some facets which can be further modified such as recognized
distance can be extended, Graphics processing unit (GPU) can be used for a large
amount of the database and quick processing, data storage can be made server-based and
can be integrated with multiple cameras at the same time.
References
https://www.irjet.net/archives/V7/i10/IRJET-V7I10219.pdf
https://www.mygreatlearning.com/blog/face-recognition/
https://www.researchgate.net/publication/267426877_Facial_Recognition_using_OpenCV
https://www.pyimagesearch.com/2018/06/18/face-recognition-with-opencv-python-and-deep-
learning/
https://techvidvan.com/tutorials/face-recognition-project-python-opencv/
14