Jose Ramon
Jose Ramon

Reputation: 5388

Using hog implementation of opencv

I want to use hog implementation of opencv in order to detect bodies in images. I found in opencv's folder samples peopledetect.cpp which are a default implementation of the hog algorithm using a pretrained model. With a little googling I found that this default approach isn't working satisfactorily. I have to create my own model using libSvm. My first question is there any tutorial or example that explains this procedure? Second one, what my model suppose to learn? What are going to be me training samples? Images that contains only people?

Edit Question: Is there a chance to train an one-class model, containing only images with people bodies? I am trying to understand the code in here. It calculates the hog features for a database and train a svm model. In evaluation process it uses the hog cascade with detectMultiScale. What is the relation of detectMultiScale with SVM?

I have train a libsvm with linear kernel with images provided from here. Images are of two kinds one that containing persons and one without persons. The train result was near to 98%(wuth svm_predict). How can I locate the position of a body inside a test image? Can I use detectmultiscale for that purpose? Feed multiscadlefunction with svm model? I have noticed in my svm model that some support vectors beggining without the label in the beggining of the line but only with the sign. Is this something normal, or it could be a bug?

Hogcascade it seems that it doesn't work for me(f.e in the image):

CascadeClassifier body_cascade;
body_cascade.load("cascades/hogcascade_pedestrians.xml");    
Mat image, gray_image;
image = imread( fileName, 1 );
resize(image, image, Size(150, 200));

vector<Rect> bodies;
cvtColor(image, gray_image, CV_BGR2GRAY);
body_cascade.detectMultiScale( gray_image, bodies, 1.3, 5 );
cout << "size of detection" << bodies.size() << endl;

Every time I am getting 0 bodies.

Upvotes: 0

Views: 2270

Answers (2)

Unapiedra
Unapiedra

Reputation: 16248

  1. Take a bunch of images containing people. You need all people marked with a rectangle around them.
  2. Convert these ROIs to HOG features (these will be positive training data). Also convert non-people areas of images to HOG features (negative training data). The HOG features need to be all of the same dimension. Have a look in the respective papers for the optimal parameters i.e. how many HOG cells per rectangle, dimensionality per HOG cell (31 normally). This requires that all rectangles have the same aspect ratio (I think).
  3. Train a classifier. Your training data is all the features you computed in the previous step, your labels are +1 for the positive training data (the HOG features referring to people) and -1 for the negative training data. You can pass both of these to libsvm. Again, read the papers to see what parameters they used for training the SVM. I'm guessing it's a linear SVM with potentially an L1 distance measure because HOGs are very much histograms and histograms don't work well with the L2 norm. But that's just a guess.
  4. Libsvm will return a model. You should test how good it is by measuring precision/recall on your test data. (Or measure ROC, or whatever you want). Libsvm has a function for this, too.

Upvotes: 2

a-Jays
a-Jays

Reputation: 1212

  1. The procedure is quite straight-forward on paper. Extract HOG features from an image, create a training vector, assign a label and give it to a classifier to learn. This would be an excellent place to experiment. I'm not sure how effective this is, but it's definitely a good source. And some wisdom here as well.
  2. Your model is supposed to learn what the HOG features of an image with a person looks like. One training sample is going to be the HOG feature vector (and not direct image itself). For the negative class, it's again going to be HOG features from images not containing people.

Upvotes: 2

Related Questions