Object Detection
Object Detection
BACHELOR OF TECHNOLOGY
IN
ELECTRONICS AND COMMUNICATION ENGINEERING
Submitted by
B. Lakshmikanth (317126512126) P. Sandhya (317126512160)
[Link]
Assistant Professor
1
ACKNOWLEDGEMENT
We would like to express our deep gratitude to our project guide [Link], Assistant
Professor, Department of Electronics and Communication Engineering, ANITS, for his/her
guidance with unsurpassed knowledge and immense encouragement. We are grateful to Dr. V.
Rajyalakshmi, Head of the Department, Electronics and Communication Engineering, for
providing us with the required facilities for the completion of the project work.
We are very much thankful to the Principal and Management, ANITS, Sangivalasa, for their
encouragement and cooperation to carry out this work.
We express our thanks to all teaching faculty of Department of ECE, whose suggestions
during reviews helped usin accomplishment of our project. We would like to thank all non-
teaching staff of the Department of ECE, ANITSfor providing great assistance in
accomplishment of our project.
We would like to thank our parents, friends, and classmates for their encouragement
throughout our project period. At last but not the least, we thank everyone for supporting us
directly or indirectly in completing this project successfully.
PROJECT STUDENTS
[Link] (317126512126)
[Link] (317126512160)
3
CONTENTS
ABSTRACT 05
LIST OF FIGURES 07
LIST OF TABLES 08
LIST OF ABBREVATIONS 09
CHAPTER 1 INTRODUCTION 10
1.1 Project objective 10
1.2 Project outline 11
CHAPTER 2 OPENCV 11
2.1 Introduction 14
2.2 Basic operations on an image 21
CHAPTER 3 OBJECT RECOGNITION MODULE 32
3.1 Haar Cascade Algorithm 32
3.2 Single Shot Detector 40
CHAPTER 4WEBSERVER USING DJANGO 40
4.1 Introduction and Installation 45
4.2 Views in Django 52
4.3 Project MVT Structure 54
CHAPTER 5HARDWARE MODEL 54
5.1 Components 57
5.2 Implementation 59
CHAPTER 6 RESULTS AND DISCUSSIONS 60
CONCLUSION 62
REFERENCES 63
PAPER PUBLICATION
4
ABSTRACT
Vision is one of the very essential human senses and it plays the most important role in human
perception of our environment, unfortunately there are many people who are visually impaired.
Blind people today rely on sighted guides, seeing-eye dogs and canes even a century after these
came into existence. The present work aims to aid the blind through a wrist wearable. The
wearable is designed to capture the user's environment through a camera and recognize the
objects present in image. These identified objects are informed to user through an audio output.
The object recognition is achieved through OpenCV.
5
LIST OF FIGURES
6
Fig.4.6 The project structure 52
Fig.5.1 The raspberry pi (hardware tool used in project) 55
Fig.5.2 A Power Bank 57
Fig.5.3 Flowchart/procedure of program 58
7
LIST OF TABLES
8
LIST OF ABBREVATIONS
9
Chapter 1
INTRODUCTION
1.1 Project Objective
Blind people lead a normal life with their own style of doing things. But, they definitely face
troubles due to inaccessible infrastructure and in new environment. It is difficult for others to
help the visually impaired all the time.
In 2015, there were an estimated 253 million people with visual impairment worldwide. Of
these, 36 million were blind and a further 217 million had moderate to severe visual
impairment (MSVI). By 2020, it is projected to 76 million people.
The need for identifying objects in the surroundings among blind people and a broader look at
the advanced technology available in today’s world is the reason to develop this project.
Object recognition is one of the fundamental tasks in computer vision. It is the process of
finding or identifying instances of objects (for example faces, dogs or buildings) in digital
images or videos.
Globally, the causes of vision impairment are cataract, uncorrected refractive errors, trachoma,
diabetic retinopathy, corneal opacity, age related muscular degeneration and eye injuries. It
limits visually impaired people to navigate and perform everyday tasks. Advancement in
technologies such as hand gesture, text recognition, Eye-ring project are came up with
solutions. However, these solutions have some disadvantages like expensive, heavyweight, less
accuracy, less speed, etc. So, the objective of the project is to design and implement a system
that captures the user’s environment through a camera module. The images that are captured
are transformed to Raspberry pi and it is analyzed using Haar Cascade and SSD Model. Then
the recognized objects are given to the user via audio through a speaker or bluetooth headset.
The image data is transferred to data server for further use.
10
1.2 Project Outline
11
Chapter 2
OPENCV
2.1 Introduction
OpenCV was started at Intel in 1999 by Gary Bradsky, and the first release came out in
2000. Vadim Pisarevsky joined Gary Bradsky to manage Intel's Russian software OpenCV
team. In 2005, OpenCV was used on Stanley, the vehicle that won the 2005 DARPA Grand
Challenge. Later, its active development continued under the support of Willow Garage with
Gary Bradsky and Vadim Pisarevsky leading the project. OpenCV now supports a multitude of
algorithms related to Computer Vision and Machine Learning and is expanding day by day.
OpenCV supports a wide variety of programming languages such as C++, Python, Java, etc.,
and is available on different platforms including Windows, Linux, OS X, Android, and iOS.
Interfaces for high-speed GPU operations based on CUDA and OpenCL are also under active
development.
OpenCV-Python is the Python API for OpenCV, combining the best qualities of the OpenCV
C++ API and the Python language.
OpenCV-Python
OpenCV-Python is a library of Python bindings designed to solve computer vision problems.
Python is a general purpose programming language started by Guido van Rossum that became
very popular very quickly, mainly because of its simplicity and code readability. It enables the
programmer to express ideas in fewer lines of code without reducing readability. Compared to
languages like C/C++, Python is slower. That said, Python can be easily extended with C/C++,
which allows us to write computationally intensive code in C/C++ and create Python wrappers
that can be used as Python modules. This gives us two advantages: first, the code is as fast as
the original C/C++ code (since it is the actual C++ code working in background) and second, it
easier to code in Python than C/C++. OpenCV-Python is a Python wrapper for the original
OpenCV C++ implementation.
OpenCV-Python makes use of Numpy, which is a highly optimized library for numerical
operations with MATLAB-style syntax. All the OpenCV array structures are converted to and
12
from Numpy arrays. This also makes it easier to integrate with other libraries that use Numpy
such as SciPy and Matplotlib.
Applications of OpenCV: There are lots of applications which are solved using OpenCV,
some of them are listed below
• face recognition
• Automated inspection and surveillance
• number of people – count (foot traffic in a mall, etc)
• Vehicle counting on highways along with their speeds
• Interactive art installations
• Anomaly (defect) detection in the manufacturing process (the odd defective products)
• Street view image stitching
• Video/image search and retrieval
• Robot and driver-less car navigation and control
• object recognition
• Medical image analysis
• Movies – 3D structure from motion
• TV Channels advertisement recognition
OpenCV Functionality
• Image/video I/O, processing, display (core, imgproc, highgui)
• Object/feature detection (objdetect, features2d, nonfree)
• Geometry-based monocular or stereo computer vision (calib3d, stitching, videostab)
• Computational photography (photo, video, superres)
• Machine learning & clustering (ml, flann)
• CUDA acceleration (gpu)
Image-Processing
Image processing is a method to perform some operations on an image, in order to get an
enhanced image and or to extract some useful information from it.
If we talk about the basic definition of image processing then “Image processing is the
analysis and manipulation of a digitized image, especially in order to improve its
quality”.
13
Digital-Image:
An image may be defined as a two-dimensional function f(x, y), where x and y are
spatial(plane) coordinates, and the amplitude of fat any pair of coordinates (x, y) is called the
intensity or grey level of the image at that point. In another word An image is nothing more
than a two-dimensional matrix (3-D in case of colored images) which is defined by the
mathematical function f(x, y) at any point is giving the pixel value at that point of an image,
the pixel value describes how bright that pixel is, and what color it should be.
Image processing is basically signal processing in which input is an image and output is image
or characteristics according to requirement associated with that image.
Image processing basically includes the following three steps:
1. Importing the image
2. Analyzing and manipulating the image
3. Output in which result can be altered image or report that is based on image analysis
14
Reading an image
import cv2
image = [Link]('[Link]')
h, w = [Link][:2]
Note – OpenCV arranges the channels in BGR order. So the 0th value will correspond to
Blue pixel and not Red.
B = image[100, 100, 0]
15
print("B = {}".format(B))
The problem with this approach is that the aspect ratio of the image is not maintained. So we
need to do some extra work in order to maintain a proper aspect ratio.
ratio = 800 / w
17
Fig(2.4):The resizing of an image
Rotating the Image
center = (w // 2, h // 2)
18
Fig(2.5): The rotation of an image
Drawing a Rectangle
It is an in-place operation.
# as it is an in-place operation.
output = [Link]()
19
Fig(2.6):The creating the bounding box/rectangle of an Image
It takes in 5 arguments –
• Image
• Top-left corner co-ordinates
• Bottom-right corner co-ordinates
• Color (in BGR format)
• Line width
Displaying text
It is also an in-place operation
output = [Link]()
20
Fig(2.7):shows the text of an image
It takes in 7 arguments –
1. Image
2. Text to be displayed
3. Bottom-left corner co-ordinates, from where the text should start
4. Font
5. Font size
6. Color (BGR format)
7. Line width
Chapter 3
OBJECT RECOGNITION MODULE
3.1 Haar Cascade Algorithm
It is an Object Detection Algorithm used to identify faces in an image or a real time video. The
algorithm uses edge or line detection features proposed by Viola and Jones in their research
paper “Rapid Object Detection using a Boosted Cascade of Simple Features” published in
2001. The algorithm is given a lot of positive images consisting of faces, and a lot of negative
21
images not consisting of any face to train on them. The model created from this training is
available at the OpenCV GitHub repository
Features
Fig. A sample of Haar features used in the Original Research Paper published by Viola and
Jones.
The first contribution to the research was the introduction of the haar features shown above.
These features on the image make it easy to find out the edges or the lines in the image, or to
pick areas where there is a sudden change in the intensities of the pixels.
22
Figure 3.2 shows the integral values of an image that converts the original image into an
integral image
Fig. The rectangle on the left is a sample representation of an image with pixel values 0.0 to
1.0. The rectangle at the center is a haar kernel which has all the light pixels on the left and all
the dark pixels on the right. The haar calculation is done by finding out the difference of
the average of the pixel values at the darker region and the average of the pixel values at the
lighter region. If the difference is close to 1, then there is an edge detected by the haar feature.
A sample calculation of Haar value from a rectangular image section has been shown here. The
darker areas in the haar feature are pixels with values 1, and the lighter areas are pixels with
values 0. Each of these is responsible for finding out one particular feature in the image. Such
as an edge, a line or any structure in the image where there is a sudden change of intensities.
For ex. in the image above, the haar feature can detect a vertical edge with darker pixels at its
right and lighter pixels at its left.
The objective here is to find out the sum of all the image pixels lying in the darker area of the
haar feature and the sum of all the image pixels lying in the lighter area of the haar feature.
And then find out their difference. Now if the image has an edge separating dark pixels on the
right and light pixels on the left, then the haar value will be closer to 1. That means, we say that
there is an edge detected if the haar value is closer to 1. In the example above, there is no edge
as the haar value is far from 1.
This is just one representation of a particular haar feature separating a vertical edge. Now there
are other haar features as well, which will detect edges in other directions and any other image
23
structures. To detect an edge anywhere in the image, the haar feature needs to traverse the
whole image.
The haar feature continuously traverses from the top left of the image to the bottom right to
search for the particular feature. This is just a representation of the whole concept of the haar
feature traversal. In its actual work, the haar feature would traverse pixel by pixel in the image.
Also all possible sizes of the haar features will be applied.
Depending on the feature each one is looking for, these are broadly classified into three
categories. The first set of two rectangle features is responsible for finding out the edges in a
horizontal or in a vertical direction (as shown above). The second set of three rectangle
features are responsible for finding out if there is a lighter region surrounded by darker regions
on either side or vice-versa. The third set of four rectangle features is responsible for finding
out change of pixel intensities across diagonals.
Now, the haar features traversal on an image would involve a lot of mathematical calculations.
As we can see for a single rectangle on either side, it involves 18 pixel value additions (for a
rectangle enclosing 18 pixels). Imagine doing this for the whole image with all sizes of the haar
features. This would be a hectic operation even for a high performance machine.
To tackle this, they introduced another concept known as The Integral Image to perform the
same operation. An Integral Image is calculated from the Original Image in such a way that
each pixel in this is the sum of all the pixels lying in its left and above in the Original Image.
The calculation of a pixel in the Integral Image can be seen in the above GIF. The last pixel at
the bottom right corner of the Integral Image will be the sum of all the pixels in the Original
Image.
24
Fig (3.3) The Integral Image is used here to calculate the haar value.
With the Integral Image, only 4 constant value additions are needed each time for any feature
size (with respect to the 18 additions earlier). This reduces the time complexity of each
addition gradually, as the number of additions does not depend on the number of pixels
enclosed anymore.
In the above image, there is no edge in the vertical direction as the haar value is -0.02, which is
very far from 1. Let’s see one more example, where there might be an edge present in the
image.
25
Fig(3.4): The Haar calculation from Integral Image.
This is a case where there is a sudden change of pixel intensities moving vertically from the
left towards the right in the image.
Again repeating the same calculation done above, but this time just to see what haar value is
calculated when there is a sudden change of intensities moving from left to right in a vertical
direction. The haar value here is 0.54, which is closer to 1 in comparison to the case earlier.
AdaBoost is a popular boosting technique which helps you combine multiple “weak
classifiers” into a single “strong classifier”. A weak classifier is simply a classifier that
performs poorly, but performs better than random guessing. A simple example might be
classifying a person as male or female based on their height. You could say anyone over 5’ 9”
is a male and anyone under that is a female. You’ll misclassify a lot of people that way, but
your accuracy will still be greater than 50%.
AdaBoost can be applied to any classification algorithm, so it’s really a technique that builds
on top of other classifiers as opposed to being a classifier itself.
What does AdaBoost do for you? There are really two things it figures out for you:
26
1. It helps you choose the training set for each new classifier that you train based on the
results of the previous classifier.
2. It determines how much weight should be given to each classifier’s proposed answer
when combining the results.
Each weak classifier should be trained on a random subset of the total training set. The subsets
can overlap–it’s not the same as, for example, dividing the training set into ten portions.
AdaBoost assigns a “weight” to each training example, which determines the probability that
each example should appear in the training set. Examples with higher weights are more likely
to be included in the training set, and vice versa. After training a classifier, AdaBoost increases
the weight on the misclassified examples so that these examples will make up a larger part of
the next classifiers training set, and hopefully the next classifier trained will perform better on
them.
The equation for this weight update step is detailed later on.
After each classifier is trained, the classifier’s weight is calculated based on its accuracy. More
accurate classifiers are given more weight. A classifier with 50% accuracy is given a weight of
zero, and a classifier with less than 50% accuracy (kind of a funny concept) is given negative
weight.
Formal Definition
To learn about AdaBoost, I read through a tutorial written by one of the original authors of the
algorithm, Robert Schapire. Let’s look first at the equation for the final classifier.
27
The final classifier consists of ‘T’ weak classifiers. h_t(x) is the output of weak classifier ‘t’ (in
this paper, the outputs are limited to -1 or +1). Alpha_t is the weight applied to classifier ‘t’ as
determined by AdaBoost. So the final output is just a linear combination of all of the weak
classifiers, and then we make our final decision simply by looking at the sign of this sum.
The classifiers are trained one at a time. After each classifier is trained, we update the
probabilities of each of the training examples appearing in the training set for the next
classifier.
The first classifier (t = 1) is trained with equal probability given to all training examples. After
it’s trained, we compute the output weight (alpha) for that classifier.
The output weight, alpha_t, is fairly straightforward. It’s based on the classifier’s error rate,
‘e_t’. e_t is just the number of misclassifications over the training set divided by the training
set size.
Here’s a plot of what alpha_t will look like for classifiers with different error rates.
28
Figure(3.5) :shows the ratio of alpha and error rate of an image
1. The classifier weight grows exponentially as the error approaches 0. Better classifiers
are given exponentially more weight.
2. The classifier weight is zero if the error rate is 0.5. A classifier with 50% accuracy is no
better than random guessing, so we ignore it.
3. The classifier weight grows exponentially negative as the error approaches 1. We give a
negative weight to classifiers with worse worse than 50% accuracy. “Whatever that
classifier says, do the opposite!”.
After computing the alpha for the first classifier, we update the training example weights using
the following formula.
29
The variable D_t is a vector of weights, with one weight for each training example in the
training set. ‘i’ is the training example number. This equation shows you how to update the
weight for the ith training example.
The paper describes D_t as a distribution. This just means that each weight D(i) represents the
probability that training example i will be selected as part of the training set.
This vector is updated for each new weak classifier that’s trained. D_t refers to the weight
vector used when training classifier ‘t’.
This equation needs to be evaluated for each of the training samples ‘i’ (x_i, y_i). Each weight
from the previous training round is going to be scaled up or down by this exponential term.
30
The function exp(x) will return a fraction for negative values of x, and a value greater than one
for positive values of x. So the weight for training sample i will be either increased or
decreased depending on the final sign of the term “-alpha * y * h(x)”. For binary classifiers
whose output is constrained to either -1 or +1, the terms y and h(x) only contribute to the sign
and not the magnitude.
y_i is the correct output for training example ‘i’, and h_t(x_i) is the predicted output by
classifier t on this training example. If the predicted and actual output agree, y * h(x) will
always be +1 (either 1 * 1 or -1 * -1). If they disagree, y * h(x) will be negative.
Ultimately, misclassifications by a classifier with a positive alpha will cause this training
example to be given a larger weight. And vice versa.
Note that by including alpha in this term, we are also incorporating the classifier’s
effectiveness into consideration when updating the weights. If a weak classifier misclassifies
an input, we don’t take that as seriously as a strong classifier’s mistake.
Practical Application
One of the biggest applications of AdaBoost that I’ve encountered is the Viola-Jones face
detector, which seems to be the standard algorithm for detecting faces in an image. The Viola-
Jones face detector uses a “rejection cascade” consisting of many layers of classifiers. If at any
layer the detection window is _not _recognized as a face, it’s rejected and we move on to the
next window. The first classifier in the cascade is designed to discard as many negative
windows as possible with minimal computational cost.
In this context, AdaBoost actually has two roles. Each layer of the cascade is a strong classifier
built out of a combination of weaker classifiers, as discussed here. However, the principles of
AdaBoost are also used to find the best features to use in each layer of the cascade.
31
Implementing Cascading Classifiers
The cascade classifier is made up of a series of stages, where each stage is a collection of weak
learners. Weak learners are trained using boosting, which allows for a highly accurate classifier
from the mean prediction of all weak learners.
Based on this prediction, the classifier either decides to indicate an object was found (positive)
or move on to the next region (negative). Stages are designed to reject negative samples as fast
as possible, because a majority of the windows do not contain anything of interest.
It’s important to maximize a low false negative rate, because classifying an object as a non-
object will severely impair your object detection algorithm. A video below shows Haar cascades
in action. The red boxes denote “positives” from the weak learners.
Haar cascades are one of many algorithms that are currently being used for object detection.
One thing to note about Haar cascades is that it is very important to reduce the false negative
rate, so make sure to tune hyper parameters accordingly when training your model.
32
3.2 Single Shot Detector
The paper about SSD: Single Shot MultiBox Detector (by C. Szegedy et al.) was released at
the end of November 2016 and reached new records in terms of performance and precision for
object detection tasks, scoring over 74% mAP (mean Average Precision) at 59 frames per
second on standard datasets such as PascalVOC and COCO. To better understand SSD, let’s
start by explaining where the name of this architecture comes from:
• Single Shot: this means that the tasks of object localization and classification are done
in a single forward pass of the network
• MultiBox: this is the name of a technique for bounding box regression developed by
Szegedy et al. (we will briefly cover it shortly)
• Detector: The network is an object detector that also classifies those detected objects
Architecture
As you can see from the diagram above, SSD’s architecture builds on the venerable VGG-16
architecture, but discards the fully connected layers. The reason VGG-16 was used as the base
network is because of its strong performance in high quality image classification tasks and its
popularity for problems where transfer learning helps in improving results. Instead of the
MultiBox
The bounding box regression technique of SSD is inspired by Szegedy’s work on MultiBox, a
method for fast class-agnostic bounding box coordinate proposals. Interestingly, in the work
done on MultiBox an Inception-style convolutional network is used. The 1x1 convolutions that
you see below help in dimensionality reduction since the number of dimensions will go down
• Confidence Loss: this measures how confident the network is of the objectness of the
• Location Loss: this measures how far away the network’s predicted bounding boxes are
from the ground truth ones from the training set. L2-Norm is used here.
Without delving too deep into the math (read the paper if you are curious and want a more
rigorous notation), the expression for the loss, which measures how far off our prediction
“landed”, is thus:
The alpha term helps us in balancing the contribution of the location loss. As usual in deep
learning, the goal is to find the parameter values that most optimally reduce the loss function,
The logic revolving around the bounding box generation is actually more complex than stated
[Link] MultiBox, the researchers created what we call priors (or anchors in Faster-R-CNN
terminology), which are pre-computed, fixed size bounding boxes that closely match the
distribution of the original ground truth boxes. In fact those priors are selected in such a way
that their Intersection over Union ratio (aka IoU, and sometimes referred to as Jaccard index) is
greater than 0.5. As you can infer from the image below, an IoU of 0.5 is still not good enough
but it does however provide a strong starting point for the bounding box regression algorithm —
it is a much better strategy than starting the predictions with random
coordinates! ThereforeMultiBox starts with the priors as predictions and attempt to
regress closer to the ground truth bounding boxes.
35
Fig (3.11): Diagram explaining IoU
The resulting architecture (check MultiBox architecture diagram above again for reference)
contains 11 priors per feature map cell (8x8, 6x6, 4x4, 3x3, 2x2) and only one on the 1x1
feature map, resulting in a total of 1420 priors per image, thus enabling robust coverage of input
images at multiple scales, to detect objects of various sizes.
At the end, MultiBox only retains the top K predictions that have minimised both location
Back onto SSD, a number of tweaks were added to make this network even more capable of
localizing and classifying objects.
36
Fixed Priors: unlike MultiBox, every feature map cell is associated with a set of default
bounding boxes of different dimensions and aspect ratios. These priors are manually (but
carefully) chosen, whereas in MultiBox, they were chosen because their IoU with respect to the
ground truth was over 0.5. This in theory should allow SSD to generalise for any type of input,
without requiring a pre-training phase for prior generation. For instance, assuming we have
configured 2 diagonally opposed points (x1, y1) and (x2, y2) for each b default bounding boxes
per feature map cell , and c classes to classify, on a given feature map of size f = m * n, SSD
Fig (3.12): shows the SSD default boxes at 8x8 and 4x4 feature maps
Location Loss: SSD uses smooth L1-Norm to calculate the location loss. While not as precise
as L2-Norm, it is still highly effective and gives SSD more room for maneuver as it does not try
to be “pixel perfect” in its bounding box prediction (i.e. a difference of a few pixels would
Classification: MultiBox does not perform object classification, whereas SSD does. Therefore,
for each predicted bounding box, a set of c class predictions are computed, for every possible
37
Datasets
You will need training and test datasets with ground truth bounding boxes and assigned class
labels (only one per bounding box). The Pascal VOC and COCO datasets are a good starting
point.
It is recommended to configure a varied set of default bounding boxes, of different scales and
aspect ratios to ensure most objects could be captured. The SSD paper has around 6 bounding
Features maps (i.e. the results of the convolutional blocks) are a representation of the dominant
features of the image at different scales, therefore running MultiBox on multiple feature maps
increases the likelihood of any object (large and small) to be eventually detected, localized and
38
appropriately classified. The image below shows how the network “sees” a given image across
During training, as most of the bounding boxes will have low IoU and therefore be interpreted
examples in our training set. Therefore, instead of using all negative predictions, it is advised to
keep a ratio of negative to positive examples of around 3:1. The reason why you need to keep
negative samples is because the network also needs to learn and be explicitly told what
Given the large number of boxes generated during a forward pass of SSD at inference time , it is
essential to prune most of the bounding box by applying a technique known as non-maximum
suppression: boxes with a confidence loss threshold less than ct (e.g. 0.01) and IoU less
than lt (e.g. 0.45) are discarded, and only the top N predictions are kept. This ensures only the
most likely predictions are retained by the network, while the more noisier ones are removed.
40
Chapter 4
Web server using Django
4.1 Introduction and Installation
Django is a Python-based web framework which allows you to quickly create web
application without all of the installation or dependency problems that you normally will find
with other frameworks.
When you’re building a website, you always need a similar set of components: a way to
handle user authentication (signing up, signing in, signing out), a management panel for your
website, forms, a way to upload files, etc. Django gives you ready-made components to use.
Why Django?
• Django is a rapid web development framework that can be used to develop fully fleshed
web applications in a short period of time.
• It’s very easy to switch database in Django framework.
• It has built-in admin interface which makes easy to work with it.
• Django is fully functional framework that requires nothing else.
• It has thousands of additional packages available.
• It is very scalable.
Django architecture
Django is based on MVT (Model-View-Template) architecture. MVT is a software design
pattern for developing a web application.
Model: Model is going to act as the interface of your data. It is responsible for maintaining
data. It is the logical data structure behind the entire application and is represented by a
database (generally relational databases such as MySql, Postgres).
View: The View is the user interface — what you see in your browser when you render a
website. It is represented by HTML/CSS/Javascript and Jinja files.
Template: A template consists of static parts of the desired HTML output as well as some
special syntax describing how dynamic content will be inserted.
41
Installation of Django
• Install python3 if not installed in your system (according to configuration of your system
and OS) from here. Try to download the latest version of python its python3.6.4 this time.
Note- Installation of Django in Linux and Mac is similar, here I am showing it in
windows for Linux and mac just open terminal in place of command prompt and go
through the following commands.
• Install pip- Open command prompt and enter following command-
python -m pip install -U pip
• Set Virtual environment- Setting up the virtual environment will allow you to edit the
dependency which generally your system wouldn’t allow.
Follow these steps to set up a virtual environment-
1. Create a virtual environment by giving this command in cmd-
virtualenvenv_site
activate
Creating a Project
Let’s check how to create a basic project using Django after you have installed it in your pc.
• To initiate a project of Django on Your PC, open Terminal and Enter the
following command
django-admin startprojectprojectName
42
• A New Folder with name projectName will be created. To enter in the project
using terminal enter command
cd projectName
Now run
Creating an App
Django is famous for its unique and fully managed app structure. For every functionality, an
app can be created like a completely independent module. This article will take you through
how to create a basic app and add functionalities using that app.
43
Fig (4.2): Shows the installed apps
To consider the app in your project you need to specify your project name in
INSTALLED_APPS list as follows in [Link]:
# Application definition
INSTALLED_APPS = [
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'[Link]',
'[Link]',
44
'projectApp'
So, we have finally created an app but to render the app using urls we need to include the app
in our main project so that urls redirected to that app can be rendered. Let us explore it.
Move to projectName->projectName -> [Link] and add below code in the header
from [Link] import include
Now in the list of URL patterns, you need to specify app name for including your app urls.
Here is the code for it –
urlpatterns = [
path('admin/', [Link]),
path('', include("[Link]")),
Django Views are one of the vital participants of MVT Structure of Django. A View is the
user interface — what you see in your browser when you render a website. It is represented
by HTML/CSS/Javascript and Jinja files. As per Django Documentation, A view function is
a Python function that takes a Web request and returns a Web response. This response can
be the HTML contents of a Web page, or a redirect, or a 404 error, or an XML document, or
an image, anything that a web browser can display.
45
Fig (4.3): shows the normal view of Django
# get datetime
import datetime
# create a function
def geeks_view(request):
46
# fetch date and time
now = [Link]()
# convert to string
# return response
return HttpResponse(html)
• First, we import the class HttpResponse from the [Link] module, along with
Python’s datetime library.
• Next, we define a function called geeks_view. This is the view function. Each view
function takes an HttpRequest object as its first parameter, which is typically named
request.
• The view returns an HttpResponse object that contains the generated response. Each view
function is responsible for returning an HttpResponse object.
urlpatterns = [
path('', geeks_view),
Types of Views
Django views are divided into two major categories :-
• Function Based Views
• Class Based Views
47
Fig (4.4): shows the classification of Django views
Let’s Create a function based view list view to display instances of a model.
let’s create a model of which we will be creating instances through our view.
In geeks/[Link],
class GeeksModel([Link]):
48
# fields of the model
description = [Link]()
def __str__(self):
return [Link]
After creating this model, we need to run two commands in order to create Database for the
same.
Now if you want to see your model and its data in the admin panel, then you need to register
your model.
Let’s register this model. In geeks/[Link],
[Link](GeeksModel)
Now we have everything ready for back end. Verify that instnaces have been created
from [Link]
49
Fig (4.5): shows the template for the django
Let’s create a view and template for the same. In geeks/[Link],
def list_view(request):
# dictionary for initial data with
# field names as keys
context ={}
<div class="main">
{{ [Link] }}<br/>
{{ [Link] }}<br/>
<hr/>
{% endfor %}
</div>
Class Based Views
Class-based views provide an alternative way to implement views as Python objects instead
of functions. They do not replace function-based views, but have certain differences and
advantages when compared to function-based views:
• Organization of code related to specific HTTP methods (GET, POST, etc.) can be
addressed by separate methods instead of conditional branching.
• Object oriented techniques such as mixins (multiple inheritance) can be used to factor
code into reusable components.
Class-based views are simpler and efficient to manage than function-based views. A
function-based view with tons of lines of code can be converted into a class-based views with
few lines only. This is where Object-Oriented Programming comes into impact.
In geeks/[Link],
51
Now create a URL path to map the view. In geeks/[Link],
from [Link] import path
<ul>
<!-- Iterate over object_list -->
{% for object in object_list %}
<!-- Display Objects -->
<li>{{ [Link] }}</li>
<li>{{ [Link] }}</li>
<hr/>
<!-- If objet_list is empty -->
{% empty %}
<li>No objects yet.</li>
{% endfor %}
</ul>
52
4.3 Project MVT Structure
Project Structure :
A Django Project when initialised contains basic files by default such as [Link], [Link],
etc. A simple project structure is enough to create a single page application. Here are the
major files and there explanations. Inside the geeks_site folder ( project folder ) there will be
following files-
53
[Link]-This file is used to interact with your project via the command line(start the
server, sync the database… etc). For getting the full list of command that can be executed by
[Link] type this code in the command window-
$ python [Link] help
folder ( geeks_site ) – This folder contains all the packages of your project. Initially it
contains four files –
54
Chapter 5
Hardware Model
5.1 Components
Raspberry Pi:
Camera Module:
The audio output is given through regular bluetooth headset or a speaker. The power supply is
provided through a power bank using a USB type A to USB type C cable.
The images that are captured are transformed to Raspberry pi and it is analyzed using Haar
Cascade and SSD Model. Then the recognized objects are given to the user via audio through a
58
speaker or bluetooth headset. The image data is transferred to Data Server for further use.
Initially, an integral image that allows very fast feature evaluation can be computed from an
image using few operations per pixel. The integral image is calculated from the original image
in such a way that each pixel in this is equal to the sum of all the pixels lying in its left and
above in the original image.
Now a method is taken for constructing a classifier by selecting a small number of important
features using AdaBoost. We use AdaBoost which selects the best features and trains the
classifiers that use them. During a detection phase, a window of the target is moved over the
input image and each subsection of the image and Haar features are calculated. The difference
is then compared to a learned threshold that separates non-objects from objects.
At last a cascade structure for combining successively more complex classifiers which
increases the speed of detector by focusing more on promising regions of the image is taken. It
consists a multiple stages, each stage is trained using a technique called Boosting. Boosting
provides the ability to train a highly accurate classifier by taking a weighted average of the
decisions made by the weak learners.
59
Results and Discussions
There are some key takeaways from the above discussed chapters. Before concluding the
report, we need to mention those points from each and every chapter. The key points we have
obtained from the project are:
• OpenCV-Python is a library of Python bindings designed to solve computer vision
problems. Compared to languages like C/C++, Python is slower. That said, Python can
be easily extended with C/C++, which allows us to write computationally intensive
code in C/C++ and create Python wrappers that can be used as Python modules. This
gives us two advantages: first, the code is as fast as the original C/C++ code (since it is
the actual C++ code working in background) and second, it easier to code in Python
than C/C++. OpenCV-Python is a Python wrapper for the original OpenCV C++
implementation.
• Haarcascade features are used for knowing the qualities of an object by which objects
can be recognized like shape, size, and edges. These can be formed by locating unique
pixels of the objects where darker and lighter pixels locate next to each other forming a
feature. Likewise, all features of the object are detected by running a rectangular
window over the image. By selecting the best features from all the features we can
detect the object by matching them with these features.
• SSD’s architecture builds on the venerable VGG-16 architecture, but discards the fully
connected layers. The reason VGG-16 was used as the base network is because of its
strong performance in high quality image classification tasks and its popularity for
problems where transfer learning helps in improving results. Instead of the original
VGG fully connected layers, a set of auxiliary convolutional layers
(from conv6 onwards) were added, thus enabling to extract features at multiple scales
and progressively decrease the size of the input to each subsequent layer.
• Django is a Python-based web framework which allows you to quickly create web
application without all of the installation or dependency problems that you normally
will find with other frameworks. When you’re building a website, you always need a
similar set of components: a way to handle user authentication (signing up, signing in,
60
signing out), a management panel for your website, forms, a way to upload files, etc.
Django gives you ready-made components to use.
• Raspberry Pi is a series of small single-board computers It is widely used in many
areas, such as for weather monitoring, because of its low cost, modularity, and open
design. It is typically used by computer and electronic hobbyists, due to its adoption of
HDMI and USB devices.
• The images that are captured are transformed to Raspberry pi and it is analyzed using
Haar Cascade and SSD Model. Then the recognized objects are given to the user via
audio through a speaker or bluetooth headset. The image data is transferred to Data
Server for further use. Image is processed at 0.3 seconds per image, hence 200 images
can be analyzed per minute.
61
CONCLUSION
To conclude with, we have proposed an assistive system for Visually Impaired group of people
in the society, which helps then recognize objects. Haar Cascade along with SSD Model is
found to be better in terms of accuracy and speed as compare to other approaches. Apart from
simulation on Python Programming, we have also done hardware implementation using
Raspberry Pi board, and other hardware equipments and hardware implementations are done
successfully. The processing time for Object recognition module
is very appropriate for this application. The Haar Cascade along with SSD Model object
recognition algorithm is highly optimized and hence the processing time can be improved
using hardware such as FPGA, DSP, and GPU etc. Generic object recognition to aid visually
impaired people is in its very early stage of development, and has a very bright future; it is a
great service for humanity to develop such a system.
Our future work includes, searching objects in real time through voice commands, date and
time information through voice commands, phone call or sending SMS through voice, Text
recognition etc.
62
REFERENCES
63
In Proceedings of the IEEE conference on computer vision and pattern recognition (pp.
7310-7311).
14. A. Heredia and G. Barros-Gavilanes, "Video processing inside embedded devices using
SSD-Mobilenet to count mobility actors," 2019 IEEE Colombian Conference on
Applications in Computational Intelligence (ColCACI), Barranquilla, Colombia, 2019,
pp. 1-6, doi: 10.1109/ColCACI.2019.8781798.
15. S. Kanimozhi, G. Gayathri and T. Mala, "Multiple Real-time object identification using
Single shot Multi-Box detection," 2019 International Conference on Computational
Intelligence in Data Science (ICCIDS), Chennai, India, 2019, pp. 1-5, doi:
10.1109/ICCIDS.2019.8862041.
16. Y. -C. Chiu, C. -Y. Tsai, M. -D. Ruan, G. -Y. Shen and T. -T. Lee, "Mobilenet-SSDv2:
An Improved Object Detection Model for Embedded Systems," 2020 International
Conference on System Science and Engineering (ICSSE), Kagawa, Japan, 2020, pp. 1-
5, doi: 10.1109/ICSSE50014.2020.9219319
64
PAPER PUBLICATION
ICT Academy is an initiative of the Government of India in collaboration with the state
Governments and Industries. ICTACT is a not-for-profit society, the first of its kind pioneer
venture under the Public-Private-Partnership (PPP) model that endeavors to train the higher
education teachers and students thereby exercises on developing the next generation teachers
and industry ready students.
ICTACT Journal on Image and Video Processing (IJIVP) is a peer – reviewed International
Journal published quarterly. IJIVP welcomes Scientists, Researchers, Academicians and
Engineers to submit their original research papers which is neither published nor currently
under review by other journals or conferences. Papers should emphasize original results
relating to both theoretical and application issues of Image and Video Processing. Review
articles, focusing on multi disciplinary views, are also welcome.
ISSN Number (Print): 0976 9099, ISSN Number (Online): 0976-9102
The paper focuses on the method used for achieving object recognition through haar cascade
algorithm integrated with single shot detector model using raspberry pi.
65