Recently, Image Feature Extraction may require HOG features. Therefore, we have studied the HOG descriptor of OpenCV. The HOG Feature Extraction function in OpenCV uses the HOGDescriptor class for encapsulation. There are also ready-made interfaces for pedestrian detection. However, there are no instructions for using this class either in the official OpenCV documentation or on Chinese and English websites. So I will share some of my experiences here.
First, go to the header file where HOGDescriptor is located to see which parameters are required by its constructor.
[Cpp]
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: DEFAULT_NLEVELS)
{}
[Cpp]
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: DEFAULT_NLEVELS)
: WinSize (_ winSize), blockSize (_ blockSize), blockStride (_ blockStride), cellSize (_ cellSize ),
Nbins (_ nbins), derivAperture (_ derivAperture), winSigma (_ winSigma ),
HistogramNormType (_ histogramNormType), L2HysThreshold (_ L2HysThreshold ),
GammaCorrection (_ gammaCorrection), nlevels (_ nlevels)
{}
[Cpp]
CV_WRAP HOGDescriptor (const String & filename)
{
Load (filename );
}
[Cpp] view plaincopy
HOGDescriptor (const HOGDescriptor & d)
{
D. copyTo (* this );
}
We can see that HOGDescriptor has a total of four constructors. The first three have the CV_WRAP prefix, indicating that they are the functions exported from the DLL, that is, the functions that can be called in the program; the last one does not have the above prefix, so we cannot use it for the moment. It is actually a copy constructor.
Next let's focus on the parameters of the previous constructor. Here we have several important parameters to study: winSize (64,128), blockSize (), blockStride ), cellSize (8, 8), nbins (9 ). These are all member variables of HOGDescriptor. The values in the brackets are their default values. They reflect the parameters of the HOG sub-statement. Here are a few examples to illustrate their meanings.
Window Size winSize
Block Size blockSize
CellSize
Gradient Direction Number nbins
NBins indicates counting the number of gradient directions in a cell. For example, if nBins is set to 9, the gradient histogram in 9 directions is collected within a cell, each direction is 180/9 = 20 degrees.
HOG description sub-Dimension
After the preceding parameters are determined, we can calculate the dimension of a HOG description sub-dimension. The HOG source code in OpenCV calculates the sub-dimension according to the following formula.
[Cpp]
Size_t HOGDescriptor: getDescriptorSize () const
{
CV_Assert (blockSize. width % cellSize. width = 0 &&
BlockSize. height % cellSize. height = 0 );
CV_Assert (winSize. width-blockSize. width) % blockStride. width = 0 &&
(WinSize. height-blockSize. height) % blockStride. height = 0 );
Return (size_t) nbins * www.2cto.com
(BlockSize. width/cellSize. width )*
(BlockSize. height/cellSize. height )*
(WinSize. width-blockSize. width)/blockStride. width + 1 )*
(WinSize. height-blockSize. height)/blockStride. height + 1 );
}
Author: xuhongwei0411