HOG parameters in the OpenCV Java version
Hello, I am developing with Android and I want to do something with my phone camera.
I’m using OpenCV-2.4.9 Java package to extract HOG features, but I’m confused about the output vector.
My image size is 480×640. I set the window to 48×64, the block size to 24×32, the cell size to 12×16, and each cell has 8 bins. So for each window, I should get a 128-dimensional data to describe it. After running the following code:
MatOfFloat keyPoints = new MatOfFloat();
Hog.compute(imagePatch, keyPoints);
keyPoints is an array with a length of 172800 (1350×128 I think). I think there should be a parameter to set Window Stride to control the number of windows. In the library, there is another function that controls the stride of the window:
public void compute(Mat img, MatOfFloat descriptors, Size winStride, Size padding, MatOfPoint locations)
But I don’t know what the parameters mean. Can anyone help me with this?
Solution
void compute(Mat img, MatOfFloat descriptors, Size winStride, Size padding, MatOfPoint locations)
Mat diagram
Enter a picture for testing
MatOfFloat descriptor
The output of the descriptor vector, one for each window in the sliding window search. In C++, it is a vector that is treated as an array, i.e. all descriptors are in the descriptors[0] of a long array. You need to know the descriptor size to get each descriptor back: Hog.getDescriptorSize().
Size winStride
size.width = the amount of overlap in the x direction of the sliding window search;
size.height = the amount of overlap of the sliding window search in the y direction;
So, if you set it to 1,1, it will check the window centered on each pixel. However, this can be slow, so you can set it to a cell size to make a good trade-off.
Size padding
This adds a border around the image so the detector can find something close to the edge. Without this, the first detection point will put half the window size into the image, so a good option is to set it to the window size or half the window size, or some order of magnitude of the cell size.
MatOfPoint location
This is a list of locations that you can specify in advance, for example, if you only need descriptors for certain locations. Leave it blank for a full search.
Example
Disclaimer: Probably not the correct java, but should give you an idea of what the parameters do….
Extract some pigs
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)