user3319734
user3319734

Reputation: 77

Extracting HOG features using openCV

I am new in OpenCV. Previously I used Matlab to compute HOG features from an image of 9x9 pixels. In Matlab I was getting feature vector of 9 values as I was using 9 bin histogram. But in OpenCV, first problem is that I am unable to run:

d.compute(imROI, descriptorsValues,Size(9,9),Size(0,0),locs); 

It seems 9x9 image is less than minimum allowed size, is it true?

Secondly, can some one please explain me all the input parameters of:

compute(const Mat& img, vector<float>& descriptors,
         Size winStride, Size padding,
         const vector<Point>& locations) const

Thanks a lot.

Upvotes: 2

Views: 8787

Answers (1)

herohuyongtao
herohuyongtao

Reputation: 50667

It seems 9x9 image is less than minimum allowed size, is it true?

It's not true.

For compute, the third parameter is Size winStride, you can use smaller values up to Size(1,1).

I guess you didn't initialize HOGDescriptor hog correctly that caused you not able to run.


If you want to only get 8 values for Size of imROI is 9x9?

The size of hog features can be computed as

num_of_hog_features = (size_t)nbins * ( blockSize.width/cellSize.width) 
                         * (blockSize.height/cellSize.height) * ((winSize.width 
                         - blockSize.width)/blockStride.width + 1) 
                         * ((winSize.height - blockSize.height)
                         / blockStride.height + 1);

So in order to get 8 values of hog feature, you can setup the parameters as follows:

HOGDescriptor *hog=new HOGDescriptor(cvSize(9,9),cvSize(9,9),
                                     cvSize(9,9),cvSize(9,9),8);
vector<float> descriptors;
hog->compute(imROI, descriptors,Size(1,1), Size(0,0));

Upvotes: 4

Related Questions