Object-Detection
Somesh Vyas
Content

OpenCV an Introduction
Haar-training
Flow-chart
Algorithm part-1
Algorithm part-2
Implementation
Code Reference
References
OpenCV an Introduction

OpenCV is an open source C++ library for image processing
and computer vision, originally developed by Intel and now
supported by Willow Garage.
It is free for both commercial and non-commercial use. It is a
library of many inbuilt functions mainly aimed at real time
image processing. Now it has several hundreds of image
processing and computer vision algorithms which make
developing advanced computer vision applications easy and
efficient.
Haar-training

The OpenCV library gives us a greatly interesting demo
for a object detection. Furthermore, it provides us
programs (or functions) which they used to train
classifiers for their object detection system (called
HaarTraining). Thus, we can create our own object
classifiers using the functions.
Flow-chart
Gather image set of
object e.g. fish

Capture stream from
camera

Gather negative image
set without object of
interest

While
capture

yes
Create vector files of
positive image set

Query frame by frame

Create dat file of
negative one’s

Convert each frame to
grayscale

haar training of positive
and negative image sets
to generate xml file

Apply histogram
equalization on image
Load haar
cascade file

Store objects to a variable
faces while using
detectMultiScale method

While
faces
yes
Draw Rectangle
on object
Algorithm part-1
Collect image set of particular object e.g. fish
Crop these images for better haarCascade file
Collect negative image set which doesn’t contain object
Use openCV createsamples utility to generate positive .vec
file for generating variations in image set
Create collection file format .dat file of negative images
using this command
$ find [image dir] -name '*.[image ext]' > [description file]
Using openCV haartraining utility we will generate xml file
which is called cascade classifier file to detect object.
Algorithm part-2

Use OpenCV for performing real time detection in
video
Use cvCaptureFromCAM to capture from camera
Use cvQueryFrame to quering frame by frame for
processing images to get ROI(Reason of Interest).
Convert image to grayscale image using
COLOR_BGR2GRAY of Imgproc class
Use Histogram Equalization method for more
accuracy.
Algorithm part-2

Using cascadeClassifier class of OpenCV load haar
cascade xml file generated in part 1 of algorithm
Use detectMultiScale method of cascadeClassifier
class to detect objects and store them in variable.
Iterate the variable so we can get all ROI
Use rectangle function to generate rectangle on ROI
Implementation

Install windows 7
Install visual studio
Install crygwin
Using crygwin generate sample training data
positive sample data as well as negative data.
Perform haartraining on sample data to generate
haar cascade xml file.
Install OpenCV
Set all environment variables according to opencv
path
Configure Visual studio project to get OpenCV
libraries
Use C++ or python for implementing algorithm
Code reference

Code reference could be found at
http://pastebin.com/Vw00NgCt
This is visual studio code for detecting object By
changing haar cascade file with haar cascade fish file
we can detect particular class of fish
References

http://note.sonots.com/SciSoftware/haartraining.html
http://docs.opencv.org/doc/tutorials/objdetect/cascade_clas
sifier/cascade_classifier.html
http://docs.opencv.org/doc/tutorials/imgproc/histograms/his
togram_equalization/histogram_equalization.html
https://opencv-pythontutroals.readthedocs.org/en/latest/py_tutorials/py_objdetec
t/py_face_detection/py_face_detection.html
http://opencv-srf.blogspot.in/2013/05/installing-configuringopencv-with-vs.html

Object detection