Eli*_*Eli 5 python opencv image-processing
我正在尝试计算视频的密集特征轨迹,如https://hal.inria.fr/hal-00725627/document中所示。我正在尝试使用 openCV hog 描述符,如下所示:
winSize = (32,32)
blockSize = (32,32)
blockStride = (2,2)
cellSize = (2,2)
nbins = 9
hog = cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins)
hist = hog.compute(img)
Run Code Online (Sandbox Code Playgroud)
然而,这会返回一个非常大的特征向量,其大小为:(160563456, 1)。
什么是窗户?(winSize) 什么是块?什么是细胞?该文档对于解释每个参数的含义并不是特别有帮助。
从http://www.learnopencv.com/histogram-of-orient-gradients/ 我看到,为了计算HOG,我们为图像块的每个单元创建一个直方图,然后对块进行标准化。
我想要的是图像的每个 (32, 32) 块的 4 个 9bin 直方图,应该根据该块的 (16,16) 单元格的直方图计算。因此,我预计 (480,640) 图像的最终 hog 特征大小为 40716。
(((32*32) / (16*16)) * 9) * (((480-16*640-16)/(32*32)*4)) = 40716
((PatchSize / 像元大小) * numBins) * numPatches = hogSize
我也见过有人做这样的事情:
winStride = (8,8)
padding = (8,8)
locations = ((10,20),)
hist = hog.compute(image,winStride,padding,locations)
Run Code Online (Sandbox Code Playgroud)
但是,我不明白locations参数的作用,因为我不希望只计算单个位置的HOG特征,而是计算图像的所有(32,32)块的HOG特征。
cell_size = (16, 16) # h x w in pixels
block_size = (2, 2) # h x w in cells
nbins = 9 # number of orientation bins
# winSize is the size of the image cropped to an multiple of the cell size
# cell_size is the size of the cells of the img patch over which to calculate the histograms
# block_size is the number of cells which fit in the patch
hog = cv2.HOGDescriptor(_winSize=(img.shape[1] // cell_size[1] * cell_size[1],
img.shape[0] // cell_size[0] * cell_size[0]),
_blockSize=(block_size[1] * cell_size[1],
block_size[0] * cell_size[0]),
_blockStride=(cell_size[1], cell_size[0]),
_cellSize=(cell_size[1], cell_size[0]),
_nbins=nbins)
self.hog = hog.compute(img)
Run Code Online (Sandbox Code Playgroud)