1/06/2016

SVM + HOG learning and detection methods using HogDescriptor

Dear Erol çıtak

This posting is for cleanning up the SVM + HOG learning and detection methods to help you.


Step 1. Prepare Data.

Prepare Positive and Negative images
Same size and gray scale

And make xml file for a more convenient data management.
Refer to this page for this step



Step 2. Training by SVM

Load positive.xml and Negative.xml and train by SVM
Refer to this page for this step 2




Step 3. Test by SVM

After training, test other images.
Refer to this page for this step 3



Step 4. for using MultiScaleDetection() 

For using Hog.MultiScaleDetection() and other functions.
We have to change the value that result of svm training. 

Refer to this page for Step 4. (There is a method for converting the end of source code)
http://study.marearts.com/2014/11/opencv-svm-learning-method-and-xml.html

after training.
refer to this source code for using method
..
//Load trained SVM xml data
FileStorage svmDX_Xml("XXXXX.xml", FileStorage::READ);
Mat xMat;
svmDX_Xml["SecondSVMd"] >> xMat;
vector< float> VX;  
//copy mat to vector  
VX.assign((float*)xMat.datastart, (float*)xMat.dataend);

//HogDescriptor
HOGDescriptor d( Size(64,64), Size(16,16), Size(8,8), Size(8,8), 9); //must be same with training setting.
d.setSVMDetector(VX);
...
d.detect(...) or d.detectMultiScale(...)

..



Thank you.