使用HOG获取图像描述符但hog.compute始终返回0.0

时间:2017-12-13 07:39:11

标签: python opencv

64x64 image 尝试使用OpenCV在Python中执行简单的操作。使用HOG获取特征向量。但我得到全部0.0。我尝试过几张相同的图片。

import cv2
image = cv2.imread("D:\\skhan\\research\\data\\face\\test.jpg",cv2.IMREAD_COLOR)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
winSize = (64,64)
blockSize = (16,16)
blockStride = (8,8)
cellSize = (8,8)
nbins = 9
derivAperture = 1
winSigma = 4.0
histogramNormType = 0
L2HysThreshold = 2.0000000000000001e-01
gammaCorrection = 0
nlevels = 64
hog = cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins,derivAperture,winSigma,histogramNormType,L2HysThreshold,gammaCorrection,nlevels)
winStride = (8,8)
padding = (8,8)
locations = ((10,20),)
hist = hog.compute(image,winStride,padding,locations)

1 个答案:

答案 0 :(得分:0)

简单地使用hist = hog.compute(image)会得到非零结果。

默认情况下winstride, padding, locations是空元组。但是,如果您坚定地使用winstride等,您的图像为64x64,窗口大小(winsize)为64x64,则添加8x8 winstride将导致窗口不重叠图像,因此您的输出用零填充。