cv2.HOGDescriptor

官方链接:https://docs.opencv.org/3.0-beta/modules/cuda/doc/object_detection.html?highlight=hogdescriptor

网上关于opencv2对hog的具体实现的资料感觉比较少,要想搞明白估计要去扣opencv2的c++源代码,c++新手感觉啃不动

Creates the HOG descriptor and detector.

C++: cuda: : HOGDescriptor::HOGDescriptor(Size win_size=Size(64, 128), Size block_size=Size(16, 16), Size block_stride=Size(8, 8), Size cell_size=Size(8, 8), int nbins=9, double win_sigma=DEFAULT_WIN_SIGMA, double threshold_L2hys=0.2, bool gamma_correction=true, int nlevels=DEFAULT_NLEVELS)

Parameters:
win_size – Detection window size. Align to block size and block stride.
block_size – Block size in pixels. Align to cell size. Only (16,16) is supported for now.
block_stride – Block stride. It must be a multiple of cell size.
cell_size – Cell size. Only (8, 8) is supported for now.
nbins – Number of bins. Only 9 bins per cell are supported for now.
win_sigma – Gaussian smoothing window parameter.
threshold_L2hys – L2-Hys normalization method shrinkage.
gamma_correction – Flag to specify whether the gamma correction preprocessing is required or not.
nlevels – Maximum number of detection window increases.
import cv2
import numpy as np

if __name__ == '__main__':

    image = cv2.imread("0.jpg")

    winSize = (20, 20)
    blockSize = (10, 10)
    blockStride = (5, 5)
    cellSize = (10, 10)
    nbins = 9
    derivAperture = 1
    winSigma = -1.
    histogramNormType = 0
    L2HysThreshold = 0.2
    gammaCorrection = 1
    nlevels = 64
    signedGradient = True

    hog = cv2.HOGDescriptor(winSize, blockSize, blockStride, cellSize, nbins, derivAperture, winSigma,
                            histogramNormType, L2HysThreshold, gammaCorrection, nlevels, signedGradient)

    winStride = (8, 8)
    padding = (8, 8)
    ans = hog.compute(image, winStride, padding)

    print(type(ans))
    print(ans)
    print(np.shape(ans))

文章目录