Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python OpenCV hog特性说明_Python_Opencv_Image Processing - Fatal编程技术网

Python OpenCV hog特性说明

Python OpenCV hog特性说明,python,opencv,image-processing,Python,Opencv,Image Processing,我正试图计算视频的密集特征轨迹,如中所示。我尝试使用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) winStride = (8,8) paddi

我正试图计算视频的密集特征轨迹,如中所示。我尝试使用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)
winStride = (8,8)
padding = (8,8)
locations = ((10,20),)
hist = hog.compute(image,winStride,padding,locations)
但是,这将返回一个非常大的特征向量大小:(160563456,1)

什么是窗户?(winSize) 什么是街区? 什么是细胞? 在解释这些参数中的每一个参数时,文档并没有特别的帮助

从 我看到,为了计算HOG,我们为图像面片的每个单元创建一个直方图,然后在面片上进行归一化

我想要的是我的图像中每个(32,32)块的4个9bin直方图,它应该从这个补丁的(16,16)个细胞的直方图中计算出来。因此,我希望(480640)图像的最终hog特征尺寸为40716

((32*32)/(16*16))*9)*((480-16*640-16)/(32*32)*4))=40716

((补丁大小/单元大小)*numBins)*numPatches=hogSize

我也见过有人这样做:

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)
winStride = (8,8)
padding = (8,8)
locations = ((10,20),)
hist = hog.compute(image,winStride,padding,locations)

但是,我不理解locations参数的作用,因为我不希望只计算单个位置的HOG特征,而是计算图像的所有(32,32)面片。

我们将图像划分为mxn像素的单元。比如说8x8。 因此,64x64图像将产生8x8像素的8x8单元

为了减少整体亮度效果,我们在特征计算中添加了一个标准化停止。一个块包含几个单元格。我们不是对每个单元进行规格化,而是对块进行规格化。32x32像素块将包含4x4 8x8像素单元

窗口是我们为其计算特征描述符的图像部分。 假设您希望在大图像中找到64x64像素的图像。然后在图像上滑动一个64x64像素的窗口,计算每个位置的特征描述符,然后使用该描述符查找最佳匹配的位置

都在文件里。只要阅读它并进行实验,直到你理解它。
如果您不能按照文档进行操作,请阅读源代码并逐行查看发生了什么。

文档和链接的文档解释窗口、块和单元格。你为什么问它是什么?关于这些解释有什么不清楚的?因此,在我的例子中,窗口大小应该是整个图像,因为我需要整个图像的描述符。文档中确实不清楚任何参数的含义。例如:块大小–以像素为单位的块大小。与单元格大小对齐。目前只支持(16,16)。如果我不知道什么是块或者什么是单元,那么它就毫无意义。更好的版本是“block_size-根据单元格数量计算归一化的块大小”@Eli-yeah文档确实不是很好。但是OpenCV是开源的,请随意贡献和改进文档。这与我链接的教程不太相符。你应该仔细检查一下。本教程以像素为单位给出了所有尺寸。我通过这种方式获得了正确数量的猪特征。(与问题略有不同,因为我意识到我误解了关于DFT的论文)。每个32x32补丁有9个箱子,有4个柱状图。我编辑了这个问题,使之与这个答案一致。
    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)