使用python从图像集中提取hog特征时出错
我试图从一组图像中提取HOG特征,但我得到的内存错误如下使用python从图像集中提取hog特征时出错,python,opencv,image-processing,Python,Opencv,Image Processing,我试图从一组图像中提取HOG特征,但我得到的内存错误如下 hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)] 记忆者 我已经从我的示例代码中复制了HOG函数 def hog(img): gx = cv2.Sobel(img, cv2.CV_32F, 1, 0) gy = cv2.Sobel(img, cv2.CV_32F, 0, 1) mag, ang =
hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
记忆者
我已经从我的示例代码中复制了HOG函数
def hog(img):
gx = cv2.Sobel(img, cv2.CV_32F, 1, 0)
gy = cv2.Sobel(img, cv2.CV_32F, 0, 1)
mag, ang = cv2.cartToPolar(gx, gy)
bins = np.int32(bin_n*ang/(2*np.pi)) # quantizing binvalues in (0...16)
bin_cells = bins[:10,:10], bins[10:,:10], bins[:10,10:], bins[10:,10:]
mag_cells = mag[:10,:10], mag[10:,:10], mag[:10,10:], mag[10:,10:]
hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
hist = np.hstack(hists) # hist is a 64 bit vector
return hist
path_url="d:/anto/preimages/"
listdir = os.listdir(path_url)
for file in listdir:
img = cv2.imread(path_url + file)
h=hog(img)
问题在于你的图像集。因为你从谷歌随机下载了图像。它可能有不同的大小,这是导致错误的原因。在调用hog函数之前,你必须调整图像的大小。在opencv中,你可以使用
resized=cv2.resize(img,(250,250))
h=hog(resized)
resolutin=(250.250)
resizes=img.resize(resolution , Image.ANTIALIAS)
在PIL库中,您可以使用
resized=cv2.resize(img,(250,250))
h=hog(resized)
resolutin=(250.250)
resizes=img.resize(resolution , Image.ANTIALIAS)
但我必须建议添加一个单独的预处理步骤。在预处理步骤中,您可以调整“preimages”文件夹中的所有图像的大小并将其保存到另一个文件夹中,您可以将其作为输入输入输入到您的hog extraction程序。preimages文件夹中的内容是什么?@Ceem Only images。我从谷歌。