Hog constructor function
Cv_wrap hogdescriptor (): Winsize (64,128), BlockSize (16,16), Blockstride (8,8), cellsize (8,8), Nbins (9), Derivaperture ( 1), Winsigma ( -1), Histogramnormtype (Hogdescriptor::l2hys), L2hysthreshold (0.2), gammacorrection (True), Nlevels ( Hogdescriptor::D efault_nlevels)
{}
   
cv_wrap hogdescriptor (size_winsize, size _blocksize, size _blockstride, Size _cellsize, int _ Nbins, int_derivaperture=1, double _winsigma=-1, int _histogramnormtype=hogdescriptor::l2hys,double _L2HysThreshold= 0.2, bool _gammacorrection=false, Int_nlevels=hogdescriptor::D efault_nlevels): Winsize (_winsize), BlockSize (_ BlockSize), Blockstride (_blockstride), cellsize (_cellsize), Nbins (_nbins), Derivaperture (_derivaperture), Winsigma ( _winsigma), Histogramnormtype (_histogramnormtype), L2hysthreshold (_l2hysthreshold), GammaCorrection (_ gammacorrection), Nlevels (_nlevels)
{}
Cv_wrap hogdescriptor (const string&filename)
{
Load (filename);
}
Hogdescriptor (const hogdescriptor& D)
{
D.copyto (*this);
}
We see that Hogdescriptor altogether has 4 constructors, the first three have cv_wrap prefixes, which indicate that they are functions derived from DLLs, that is, functions that we can invoke in our programs.
Hog Basic Concepts
In the constructor, there are several parameters that are important, winsize (64,128), BlockSize (16,16), Blockstride (8,8), cellsize (8,8), Nbins (9). Here, with a few to express.
A) window size winsize
b) Block Size blocksize
c) Cell size cellsize
d) Number of gradient directions
The nbins represents the number of directions in which the gradient is counted in a cell. For example: nbins=9 represents a gradient histogram in 9 directions within a cell.
The calculation of Hog feature dimension
First give a hog
hogdescriptor* hog = Newhogdescriptor (Cvsize (), Cvsize (8, 6), Cvsize (8, 6), Cvsize (4, 3), 9);
According to the above concept, Cvsize (64,48) indicates the size of the window, Cvsize (8, 6) represents the block size, Cvsize (8,6) represents the block sliding increment (blockstride) size, Cvsize (4, 3) Represents the cell size, and 9 represents the number of gradient histograms in each cell.
Note: The image size entered is 640x480.
According to this, we know:
A block contains a a= (blocksize.width/cellsize.width) * (blocksize.height/cellsize.height) cell (cell), So a block contains 9A gradient histograms. According to the data given, the result is 36.
A window containing b= ((windowsize.width-blocksize.width)/(blockstridesize.width) +1) * ((windowsize.height-blocksize.height)/( Blockstridesize.height) (block) +1), so a window contains 9AB gradient histograms.
According to the data given, the result is 2304.
Next, compute the eigenvector hog->compute (trainimg,descriptors, size (up to), size (0, 0))
Here, trainimg represents the imported picture (in this case, 640x480), descriptors indicates that the Vector,size (64,48) that holds the result of the feature represents the stepping of windows, and the fourth is padding, which fills the picture to fit the size.
When padding is in the default state size (0,0), sliding Windows window to calculate the picture,
The result is not necessarily an integer.
At this point, look at the compute () function discovery, which has a section of code as follows:
Padding.width = (int) alignsize (Std::max (padding.width,0), cachestride.width);
Padding.height = (int) alignsize (Std::max (padding.height,0), cachestride.height);
This code is used to adapt the size of the padding to the size of the stride.
In my case, all of the numbers have been designed in advance and are integers. When the result is not an integer, it is evaluated to be the smallest integer larger than its value. If the padding.width is calculated as 7.8, take 8.
Therefore, a picture of 640x480, according to the previous parameters, you can take the number of features 230400-dimensional.
Here, special thanks to several, respectively:
Http://www.cnblogs.com/tornadomeet/archive/2012/08/15/2640754.html
This blog post summarizes some of the online references, using the Hog feature training process and explaining the hog code in the OpenCV.
http://blog.csdn.net/raocong2010/article/details/6239431
This blog post provides a detailed explanation of the concept of Block,cell in hog. The images in my blog post are from this post. Thank you so much.
Http://gz-ricky.blogbus.com/logs/85326280.html
This post explains in detail the calculation of the number of features in hog.
Introduction of hog parameters and calculation of Hog feature dimension (RPM)