Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HOG parameters in OpenCV Java Version

Hi I am developing in Android and I want to use my cellphone camera to do something. I am using OpenCV-2.4.9 Java package to extract HOG feature, but I am confused about the output vector.

My image size is 480x640. I set the window to be 48x64, blocksize 24x32, cellsize 12x16 and 8 bins for each cell. So for each window, I should get a 128 dimension data to describe it. After running the following code:

MatOfFloat keyPoints = new MatOfFloat();
Hog.compute(imagePatch, keyPoints);

keyPoints is a array whose length is 172800 (I think it is 1350x128). I think there should be a parameter to set the window stride to control the number of windows. In the library, there also another function to control the window stride:

public  void compute(Mat img, MatOfFloat descriptors, Size winStride, Size padding, MatOfPoint locations)

but I dont know the meaning of the parameters. Could anyone help me to figure this out?

like image 590
user3783676 Avatar asked Dec 19 '22 13:12

user3783676


1 Answers

void compute(Mat img, MatOfFloat descriptors, Size winStride, Size padding, MatOfPoint locations)

Mat img

input image to test

MatOfFloat descriptors

output vector of descriptors, one for each window in the sliding window search. in c++ it is an vector treated as an array, that is all descriptors are in descriptors[0] in one long array. You need to know the descriptor size to get back each descriptor: Hog.getDescriptorSize() .

Size winStride

size.width = the amount of overlap in the x direction for the sliding window search;

size.height= the amount of overlap in the y direction for the sliding window search;

So if you set it to 1,1 it will check a window centered on every pixel. However this will be slow, so you can set it to the cell-size for a good trade-off.

Size padding

This adds a border around the image, such that the detector can find things near to the edges. without this the first point of detection will half the window size into the image, thus a good choice would be to set it to the window size or half the window size, or some order of the cell size.

MatOfPoint locations

This is a list of locations that you can pre-specify, for instance if you only want descriptors for certain locations. Leave it empty to do a full search.

Example

disclaimer: may not be proper java, but should give you an idea what the parameters do...

Extract some Hogs

    MatOfFloat descriptors(0) //an empty vector of descriptors
    Size winStride(Hog.width/2,Hog.height/2) //50% overlap in the sliding window
    Size padding(0,0) //no padding around the image
    MatOfPoint locations(0) ////an empty vector of locations, so perform full search        

    compute(img , descriptors, winStride, padding, locations)
like image 101
QED Avatar answered Jan 02 '23 09:01

QED