Ask Your Question
1

TRAIN_HOG.cpp

asked 2017-12-07 15:46:30 -0600

AP108 gravatar image

updated 2017-12-08 09:06:01 -0600

Hello! To begin with, I'm new to the opencv world so my questions about the implementation of train_hog.cpp, may be of basic nature.

A)First of all, in the main() what's the purpose of the line:

                   pos_image_size = pos_image_size / 8 * 8;

B)In the function computeHOGs, the choice of the specific part of the image(instead of starting from 0,0):

             Rect r = Rect(( img_lst[i].cols - wsize.width ) / 2,
                      ( img_lst[i].rows - wsize.height ) / 2,
                      wsize.width,
                      wsize.height);

is done in order to capture the region which probably has more information (a more 'central')?

C)In get_svm_detector function what's the meaning of

           hog_detector[sv.cols] = (float)-rho;

Thanks in advance and sorry for the multiple questions...

edit retag flag offensive close merge delete

Comments

hi @AP108 thank you for your question. i can answer A and B ( as the coder of related lines ). but before answering can i ask "do you have sample positive images and what is their dimensions" may be i will give some hints to change the code according to your needs. indeed train_HOG is only a sample ( not an official app like traincascade) so it doesn't cover all possibilities of training a HOG detector.

sturkmen gravatar imagesturkmen ( 2017-12-08 10:08:00 -0600 )edit

Actually, no I don't have sample images, not yet at least. Mainly, I wanted to familiarize with the general steps that have to be followed regarding HOG n SVM.

AP108 gravatar imageAP108 ( 2017-12-10 06:35:15 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2017-12-08 12:07:05 -0600

let me try to explain usage of train_HOG.cpp

what we need to prepare

1. we need positive samples gathered in a directory (as much as we have positive samples we can train a better detector)

here is some good positive image samples from INRIA Person Dataset cropped for train a HOG detector which has 64x128 window size

image description image description image description

2. we need Images don't include objects that we want to detect gathered in a directory ( for beginning i advise negative image count should not be less than positive images count)

like the image below ( also taken from INRIA Person Dataset (it has pedestrians but they are too small according to 64x128 window size ))

image description

---

lets suppose you put positive samples in c:/pos and negative images in c:/neg

here is some possible cmd line parameter usage

cpp-example-train_HOG -pd=c:/pos -nd=c:/neg

if all your positive samples have the same dimension you will get my_detector.yml

winSize is calculated according to your pos images size (96x160 for positive images above ) using the line below

pos_image_size = pos_image_size / 8 * 8;

lets add -dw -dh params like

cpp-example-train_HOG -dw=64 -dh=128 -pd=c:/pos -nd=c:/neg

now we specified winSize as 64x128 but our positive images are 96x160 so the program uses central 64x128 rect for training

         Rect r = Rect(( img_lst[i].cols - wsize.width ) / 2,
                  ( img_lst[i].rows - wsize.height ) / 2,
                  wsize.width,
                  wsize.height);
edit flag offensive delete link more

Comments

i will try to improve this answer later to be more general

sturkmen gravatar imagesturkmen ( 2017-12-08 12:10:20 -0600 )edit

Thank you very much for your answer.

AP108 gravatar imageAP108 ( 2017-12-09 15:49:19 -0600 )edit
1

answered 2017-12-08 04:14:58 -0600

  1. The code is in a structured loop, but to mee it seems that there is a check if your image actually has a dimensions corresponding to the HOG window that is being used. If not, it will generate issues later down the line.
  2. There is nothing random in it .... how do you come to that conclusion?
  3. This is a specific setting of the SVM parameters ... the sample shows you how to adapt it, but for basic purposes you do not even need it.
edit flag offensive delete link more

Comments

1

3: wait ! the hogdetection does a straight dot product between the sample and the svm support vector. rho is the threshold value for the decision (did we find something or not ?)

so, the value is needed there ! (but ppl probably don't need to know about it's specific meaning)

berak gravatar imageberak ( 2017-12-08 04:48:03 -0600 )edit

ah you are correct, as always :D

StevenPuttemans gravatar imageStevenPuttemans ( 2017-12-08 04:53:36 -0600 )edit

Thanks for your immediate answers. 2. Actually I misphrased. We chose the specific start of the Rect (instead of 0,0) in order to capture the region which probably has more information?

AP108 gravatar imageAP108 ( 2017-12-08 08:59:32 -0600 )edit

maybe @sturkmen has a better explanation for that

berak gravatar imageberak ( 2017-12-08 10:03:41 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-12-07 15:46:30 -0600

Seen: 725 times

Last updated: Dec 08 '17