Ask Your Question

# Custom HOGDetector using CvSVM and HOG features.

I'm trying to train my own detector for use with OpenCV::HOGDescriptor but I'm having trouble making the existing HOGDescriptor work with my newly trained SVM.

I have calculated HOG features for positive and negative training images, labeled them and trained the SVM using CvSVM. The parameters I have used are:

CvSVMParams params;
params.svm_type =CvSVM::EPS_SVR;
params.kernel_type = CvSVM::LINEAR;
params.C = 0.01;
params.p = 0.5;


Then I calculate Primal Form of the support vectors so that I only get one vector instead of many and set the calculated support vector using HOGDescriptor.setSVMDetector(vector);

This is primal form.

When I use CvSVM.predict() I am able to correctly classify objects with the SVM with high accuracy, but HOGDescriptor.detect() or detectMultiScale() always returns a lot of positive matches and does not give accurate predictions.

Here is my code for flattening the vector.

My trained svm model file

I am not able to find much information about how to make the trained svm model work with HOGDescriptor. CvSVM.predict() uses the original trained support vectors for classification so there might be something wrong with the way I'm calculating primal form to feed into HOGDescriptor.setSVMDetector(). Have anyone tried something similar and can point me in the right direction?

edit retag close merge delete

## 2 answers

Sort by » oldest newest most voted

Ok I guess I can have a go at trying to answer your problem right now.

As far as I see you are mixing up two things. The detect and detectMultiScale are two algorithms that are used with the xml cascade classifiers created by the traincascade algorithm.

However I know they can also be used for classification with a SVM model, since it is done in the latentSVM example, based on the Felzenszwalb detector. However, since I did not manually train a SVM model yet (not there yet in my research - still doing cascade classifiers first) I would suggest checking the following stuff:

1) Did you cross referenced your model with the existing pedestrian model in the resource folder of OpenCV? Do you have the same structure? The same parameters? The same elements?

2) A problem with using SVM detector is that you define support vectors based on a maximal margin approach using slack variables to determine the allowed mistakes. However, you always do it based on the provided data an the estimated data distribution from this. Can you point out how many samples you used? It is possible that you did not sample background from object enough, being negatives and positives.

Get back to me with the numbers please.

more

## Comments

Actually, I tried training again with a lot of training images from a fixed environment. ( Just a table next to a black wall, with and without a cup on it). Now the HOGDetector.detectMultiScale is able to detect the cup very precisely! So I guess it was just my trainingdata / parameters that was badly tuned. I guess I have to be more careful when choosing training images and be patient when tuning my parameters. I am not sure what resource folder you are talking about so I have not cross referenced my parameters towards the pedestrian detector as I am not able to find anything. Thanks for your reply Steven.

( 2013-03-12 07:05:16 -0500 )edit

Be aware of the following: since you just sampled negatives from a fixed environment, your detector will only perform well in this environment. This means that there is actually no training of the background variation, since this is static. However, if this is what you actually need it for, then it will work. If you want to detect cups in totally randomn scenes, you will need to sample as variate sceneries as possible, in order to create a good background/environment clutter model.

( 2013-03-12 07:14:25 -0500 )edit

Actually what I want to do is to train the detector to find people in wheelchairs in city streets. I know this is not a simple task, but wouldn't it be similar to detecting pedestrians in city streets? For example replacing the training data from http://pascal.inrialpes.fr/data/human/ with pictures of people in wheelchairs instead of walking pedestrians. Do you think this sounds like a feasible idea?

( 2013-03-12 08:51:27 -0500 )edit

It is a feasible idea. We have been doing research in the same area. However there are a couple of things you should consider. City street area's are one of the most versatile locations you can actually have. This means a lot of variations of the scenery. To actually model this diversity, a large numbers, maybe even order 10^8 negative samples will be needed. Then a second problem arises. A sitting person in a wheelchair has many different orientations to view at. You could start with constrained orientations, training in very controlled environments, but you will have to figure out how to cope with all these variations. This is one of the main research topics of computer vision conferences around the world, so just go to the internet, and go search papers! :)

( 2013-03-12 09:38:27 -0500 )edit

First of all, placing a link to another forum is just simply being lazy. People prefer to see a clear question, just like you did on stackoverflow.

Referring to this question, here you ask about problems with detect and detectMultiScale, on stackoverflow it is about how to train a self made model.

So please state your question clearly here, tell us what error is occuring, and then we will be able to help you out ...

more

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2013-03-11 08:50:42 -0500

Seen: 4,529 times

Last updated: Mar 12 '13