Hog wherein parsing the source opencv (6): hog source analysis

Hog module division:

First, clear a few concepts in the figure below:

image: the entire picture; win form: the blue section; block: red section; cell: four green part of the red section;

Dalal Hog feature extraction process proposed: the sample image is divided into a plurality of pixel units (cell), the average gradient direction is divided into nine sections (bin), gradient direction in each direction of all pixels in each cell inside interval histogram statistics to give a 9-dimensional feature vector, each of the four adjacent cells constitute one block (block), the feature vectors within blocks linked together to give a 36-dimensional feature vectors, with the block sample images scan, scan step size as a unit. Finally, the feature blocks all together, and get the body's characteristics. For example, for an image of 128 * 64, the 8 * 8 pixels each composed of a cell, each cell consisting of 2 * 2 block, because each cell has nine features, it is within each block 4 * 9 = 36 wherein, in steps of eight pixels, then the seven horizontal direction scan window, there will be 15 in the vertical direction scan window. That is, 64 * 128 images, a total of 36 * 15 * 7 = 3780 features.

HOG dimension, 16 × 16 pixel block composed, 8x8 pixel cell

       We know that the use of the sliding frame Hog achieved, then leads to a concept: step; Bloc the step, win the step, cell of the bin;

Generally; win is the topmost feature calculation unit; that is, a win all the parameters of the corresponding target;

block generally less than win, win the width and height of the block is typically an integer multiple of the width and height; thus block when the block is traversed step win, how many pixels the slide;

Block size by the size of the sell for reference; not slide Cell (FIG: Hog feature calculation)

cell of bin What does it mean?

    Earlier we studied gradient, the gradient is calculated at each pixel, comprising the gradient magnitude and direction; direction and about which the bin;

0-360 is a circle, a circle divided every 40 degrees, a total of nine; this is the bin; a divided every 40 degrees; a · bin = 40 degrees (FIG: Hog feature calculation)

A cell to include a full 360 degree information, is just 9 bin;

     As we mentioned harr a feature value is obtained (white - black); and wherein Hog ​​is obtained a vector (the vector dimension);

Dimension = block number * number of cell cell number in the bin of the Hog *;

 

     The win is officially recommended size 64 * 128; 16 × 16 pixel block composed, 8x8 pixels Cell; block step size of 8 pixels; the block count = ((64-16) / 8 + 1) * (128- 16) / 8 + 1) = 105 block;

 

A block = 4 th cell (16 * 16 = 2 * (8 * 8)); and cell1,2,3,4;

 

HOG Dimension = 105 * 4 * 9 = 3780;

 

Mentioned gradient, we know that hog get is a vector, then how hog gradient to calculate it?

Harr calculated in a manner similar to use feature template;

Template levels: [0 1 -1], vertical templates: [[1] [0] [-1]];

The product of the template and the corresponding pixel:

 

The magnitude of the gradient √ = (A 2 + B 2 ), the angle = arctan (a / b)

Mentioned gradient, the gradient is based on pixels, each pixel has a gradient; gradient calculation know, that bin projection how to calculate it

As mentioned above 0-360 degrees is a circle, a circle divided every 40 degrees, a total of nine; this is the bin; a division of each of 40 degrees; a · bin = 40 degrees (FIG: Hog characteristic calculation),

0-40 of each bin size is not continuous, that is 0-40 degrees two bin belongs projected; bin is continuous only 0-20, 20-40 is a contiguous block;

And bin1: 0-20, 180-200; both blocks belong to a projection bin; follows:

For a pixel i, j; gradient magnitude which f, is the angle a;

If a = 10; it is projected bin1; if a = 190, it is also projected bin1

How it is calculated that the magnitude of f:

Method 1 (refer to: the HOG features principle ): https: //blog.csdn.net/q1007729991/article/details/53032776

 

Method 2: Reference: the HOG features : https: //www.zhihu.com/collection/282778463

 

 

 

 To summarize Hog features:

HOG features:

       Gradient direction histogram (Histogram of Oriented Gradient, HOG) used is a characteristic feature of the object detected in the computer vision and image processing descriptor. Characterized in that it is constituted by the gradient direction histograms and statistical calculation of the local region image. Hog SVM classifier binding characteristics have been widely used in image recognition, in particular pedestrian detection obtained great success.

HOG feature extraction method is an image (your target to be detected or scanning window):

1) of the gradation (the image seen as a x, y, z (gradation) of the three-dimensional image);

2) Gamma correction method using the input image color space standardized (normalized); object of adjusting the contrast of the image, and reduce the impact of illumination shading caused local change of the image, and can suppress the noise interference;

3) calculating a gradient image for each pixel (including magnitude and direction); primarily to capture the outline information, and further weakening of the interference light.

4) The image is divided into small cells (e.g. 6 * 6 pixels / cell);

5) a gradient histogram statistics for each cell (the number of different gradients), to form a descriptor of each cell;

6) The composition of a cell block every several (e.g. 3 * 3 cell / block), a characteristic descriptor in all cell block are connected in series will give HOG feature descriptor of the block.

7) will feature all HOG block in the image image descriptor in series can get the image (target) you want to detect the HOG feature descriptor.

 

下面这篇文章一定需要好好看看:opencv源码解析之(6):hog源码分析

 

参考:OpenCV+TensorFlow 入门人工智能图像处理

Hog特征提取 openCV:这篇文章中开头参考的大神讲的好;

Guess you like

Origin www.cnblogs.com/fcfc940503/p/11344519.html