3. 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.
4. 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.
5. 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
6. Load haar
cascade file
Store objects to a variable
faces while using
detectMultiScale method
While
faces
yes
Draw Rectangle
on object
7. 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.
8. 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.
9. 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
10. 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
11. Set all environment variables according to opencv
path
Configure Visual studio project to get OpenCV
libraries
Use C++ or python for implementing algorithm
12. 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