我正在尝试从一组图像中提取HOG功能,但是由于
hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]
内存错误
我已经从opencv示例中复制了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)
问题在于您的图片集。由于您是从google随机下载的图片。它的大小可能不同,这会导致错误。在调用hog函数之前,您必须调整图片的大小。在opencv中,您可以使用
resized=cv2.resize(img,(250,250))
h=hog(resized)
在PIL库中,您可以使用
resolutin=(250.250)
resizes=img.resize(resolution , Image.ANTIALIAS)
但是我必须建议添加一个单独的预处理步骤。在预处理步骤中,您可以将“ preimages”文件夹中的所有图像调整大小并将其保存到另一个文件夹中,并将其作为输入到生猪提取程序中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句