OpenCV中的HOGDescriptor 函数

1、函数原型声明和相应参数的解释

在这里告诫大家,关于OpenCV中一些函数的使用,最好去读英文原版注释,这样才能更深刻的去了解用途。
函数原型:
cv2.HOGDescriptor(win_size = (64, 128),  
                  block_size = (16, 16),  
                  block_stride = (8, 8),  
                  cell_size = (8, 8),  
                  nbins = 9,  
                  win_sigma = DEFAULT_WIN_SIGMA,  
                  threshold_L2hys = 0.2,  
                  gamma_correction = true,  
                  nlevels = DEFAULT_NLEVELS)

具体参数介绍(parameters):
win_size – Size ##窗口的大小
Size of detection window in pixels (width, height). Defines the region of interest. Must be an integer multiple of cell size.
block_size – Size ## 块的大小
Block size in pixels (width, height). Defines how many cells are in each block. Must be an integer multiple of cell size and it must be smaller than the detection window. The smaller the block the finer detail you will get.
block_stride – Size ## 块的步幅
Block stride in pixels (horizontal, vertical). It must be an integer multiple of cell size. The block_stride defines the distance between adjecent blocks, for example, 8 pixels horizontally and 8 pixels vertically. Longer block_strides makes the algorithm run faster (because less blocks are evaluated) but the algorithm may not perform as well.
cell_size – Size ## 包的大小
Cell size in pixels (width, height). Determines the size fo your cell. The smaller the cell the finer detail you will get.
nbins – int ## 直方图的条数(bins)
Number of bins for the histograms. Determines the number of angular bins used to make the histograms. With more bins you capture more gradient directions. HOG uses unsigned gradients, so the angular bins will have values between 0 and 180 degrees.
win_sigma – double ##
Gaussian smoothing window parameter. The performance of the HOG algorithm can be improved by smoothing the pixels near the edges of the blocks by applying a Gaussian spatial window to each pixel before computing the histograms.

这个参数的意思是:在计算直方图之前,通过在每个像素上加入高斯空间窗口,平滑块边缘附近的像素,可以提高HOG算法的性能。

threshold_L2hys – double ###用于规范化,默认值是 0.2
L2-Hys (Lowe-style clipped L2 norm) normalization method shrinkage. The L2-Hys method is used to normalize the blocks and it consists of an L2-norm followed by clipping and a renormalization. The clipping limits the maximum value of the descriptor vector for each block to have the value of the given threshold (0.2 by default). After the clipping the descriptor vector is renormalized as described in IJCV, 60(2):91-110, 2004.
gamma_correction – bool ## 在这里用于标名是否使用 gamma 预处理
Flag to specify whether the gamma correction preprocessing is required or not. Performing gamma correction slightly increases the performance of the HOG algorithm.
nlevels – int
Maximum number of detection window increases.

2、大致用法:

As we can see, the cv2.HOGDescriptor() function supports a wide range of parameters. The first few arguments (block_size, block_stride, cell_size, and nbins) are probably the ones you are most likely to change. The other parameters can be safely left at their default values and you will get good results.

For example, we usually use the cv2.HOGDescriptor() function to set the cell size, block size, block stride, and the number of bins for the histograms of the HOG descriptor. We will then use .compute(image) method to compute the HOG descriptor (feature vector) for the given image.

猜你喜欢

转载自blog.csdn.net/qq_18649781/article/details/88828157