Haartraining for pedestrian

Page 1

opencv:tutorial:haartraining [AIT Computer Vision Wiki]

1 di 6

https://webeng.cs.ait.ac.th/cvwiki/opencv:tutorial:haartraining

HaarTraining for Pedestrian Detection Introduction This tutorial steps you through the process of training a pedestrian detector using Viola and Jones’ cascaded classifier approach using the implementation of their “Boosted Cascade of Simple Features” built into OpenCV.

Platform Used MS VC++ OpenCV

Utilities Used This tutorial is based on haartraining, the object detection program built into OpenCV. The programs we’ll use are shown in this table: Program used

Path (MS Windows default installation)

Explanation

Results

createsamples.exe

C:\Program Files\OpenCV\bin\createsamples.exe

Forms training/testing Creates vectors in a .dat vectors from image file that can be imported pixel values into haartraining

haartraining.exe

C:\Program Files\OpenCV\bin\haartraining.exe

Trains a classifier Creates a classifier cascade on a training description that can be set tested or deployed.

performance.exe

C:\Program Files\OpenCV\bin\performance.exe

Tests a trained Outputs detection rates classifier cascade on and false alarm rates on test data the given data set.

Training Process The steps of the training process are shown in this figure:

I lead you through each of the four steps below.

25/05/2008 7.49


opencv:tutorial:haartraining [AIT Computer Vision Wiki]

2 di 6

https://webeng.cs.ait.ac.th/cvwiki/opencv:tutorial:haartraining

Step 1: DataSet Dataset collection consists of two steps.

Image Acquisition For the image acquisition process, images can be acquired from anywhere likes streets wherever you can find a pedestrians by using Web cameras, digital cameras, or video. The collection of dataset consists of collection of positive samples and collection of negative samples. Then divide the positive samples into training set and testing set (If you have 100 images, divide it into 95 for training and 5 for testing)

For simplicity its better to place the Positive and Negative samples in the different folders. Training the pedestrians is hard since they are not stable (varying with poses). Its better to collect at least 5-6 samples per person with different pose. Give below is the collection positive samples.

Prepraration of Training Set OpenCV has bulit in training system to construt a classifier, for training purpose the system works quite well. OpenCV generates the sampels images for you that will be used for training putprose. The program used for creating samples using OpenCV is createsamples.exe and The command used is -createsamples Inorder to use this command we need to fed the system with the postive samples that are collected during Image Acquisation stage. We cannot fed the image directly to the training system as it only recognizese the numeric values (x, y, width, height)which is the location of pedestrain in an image. The next step is to localize the the pedestrain in a image and find the no. of pedestrain in an image, x co-rodinate, y co-ordiante, width, height. At the bottom of this tutorial is the cropping program, I modified the online tutorial from sourceforge.net LkDemo (http://sourceforge.net/projects/opencv/ [http://sourceforge.net/projects/opencv/]) to capture the images from the video sequence and to crop the image. Download the source code from the Reference Section Filename : CV_TrainingPede.zip Run the CVTraining_Prj.exe (you should be connected to the webcam for using this program) Load the positive samples from the PositiveSamples folder, in CV_TrainingPrj.cpp the location for PositiveSample folder and PositiveSample.txt is placed in C:\Program Files\OpenCV\bin, you can specify the location of the file in the program to

25/05/2008 7.49


opencv:tutorial:haartraining [AIT Computer Vision Wiki]

3 di 6

https://webeng.cs.ait.ac.th/cvwiki/opencv:tutorial:haartraining

any location you want for that just just change the path for C:\Program Files\OpenCV\bin\PositiveSample\image00.bmp to any other location. * Use the mouse to localize the pedestrains in an image.

This program will : save the crop image file in Files\OpenCV\bin\Cropped_Images\output00.bmp generates the PositiveSample.txt which is Files\OpenCV\bin\PositiveSample.txt. This txt files includes:

directory saved

C:\Program in

C:\Program

The red rectangle is the crop window. Now, the all of the positive samples are cropped and location of pedestrains are found we can use command “-createsamples� from OpenCV to Create the samples. Note that while cropping you should always maintain aspect ratio for w:h,as not considering aspect ration will results construction of poor classifier.

Creating training and testing samples using ''createsamples'' For the sample creation step, do the following: 1. From the command prompt, go to the location where OpenCV is installed (C:\Program

Files\OpenCV\bin) and check in the bin\ folder if all the three .exe files are present or not. 2. To show the parameters that can be used for creating the samples: C:\Program Files\OpenCV\bin> cd createsamples 1. To create the samples: C:\Program Files\OpenCV\bin> createsamples -info PositiveSample.txt -num 166 -show -w 15 -h 20 -vec CreateSample.dat > createsample.log

The vector file CreateSample.dat will be used during training the classifier. This completes the Step 1.

Step2: Training using AdaBoost Training samples using OpenCV is based on AdaBoost approach.

The main goals of the AdaBoost learning algorithm are: Selecting a few set of features which represents features as well as possible pedestrains Train the Strong Classifier which the linear combination of these best features

25/05/2008 7.49


opencv:tutorial:haartraining [AIT Computer Vision Wiki]

4 di 6

https://webeng.cs.ait.ac.th/cvwiki/opencv:tutorial:haartraining

The haartraining command is used for training the classifier. - C:\Program Files\OpenCV\bin> cd haartraining This will show all the parameters that can be used for training the classifier.

- To create the samples use this command, C:\Program Files\OpenCV\bin> haartraining - data TrainingSample -vec CreateSample.dat -npos 166 -bg Negative -mem 500 -nonsys -mode ALL -w 15 -h 20 > TrainingSample.log

This command will result in cascade of classifier in TrainingSample folder. For detection this cascade of classifier should be converted in xml format. The converter cascade to xml file is not available in OpenCV. This file can be downloaded from: http://tech.groups.yahoo.com/group/OpenCV/files/cascade2xml.c [http://tech.groups.yahoo.com/group/OpenCV/files/cascade2xml.c].

Download the file and create cascade2xml.exe file and place this cascade2xml.exe in the bin folder like others. Converting Cascade to Xml - Run the command C:\Program Files\OpenCV\bin> cascade2xml TrainingSample/ XMLFileForDetection.xml 15 20

This xml file is the classifer that is used for detecting pedestrains. This completes Step 2

Step 3: Testing The testing data should be different from the training data. Performance command is used for testing or detecting purpose. The format of the testing data should be:

25/05/2008 7.49


opencv:tutorial:haartraining [AIT Computer Vision Wiki]

5 di 6

https://webeng.cs.ait.ac.th/cvwiki/opencv:tutorial:haartraining

testsample.txt file format

Step 4: Run Performance Program Place TestingSample.txt in the folder TestingImages, if you do not put the TestingSample.txt into TestingImage then performance program will execute but will not save and show any result Go to the command line and run: C:\Program Files\OpenCV\bin> performance -data TrainingSample.xml -info TestingSample\testsample.txt -sf 1.2

Results Results of performance (testing) will be saved inside the folder testsample with the prefix det 1. det-testimage00.bmp 2. det-testimage01.bmp and so on

Thin red rectangle is the location of the pedestrain which is defined in TestingSample.txt. Thick red rectangle is the detected location of pedestrain after running the performance program.

References Here is the complete code and a list of useful papers.

Code CV_TrainingPede.zip

25/05/2008 7.49


opencv:tutorial:haartraining [AIT Computer Vision Wiki]

6 di 6

https://webeng.cs.ait.ac.th/cvwiki/opencv:tutorial:haartraining

Publications Viola_and_Jones_PedestrainDetection.pdf Rapid_Object_Detection_Viola_and_Jones.pdf

opencv/tutorial/haartraining.txt 路 Last modified: 2007/08/06 14:53 by mdailey

25/05/2008 7.49


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.