4

I am trying to extract HOG features from set of images But i am getting Memory Error as

hists = [np.bincount(b.ravel(), m.ravel(), bin_n) for b, m in zip(bin_cells, mag_cells)]

MemoryError

I have copied HOG function from opencv example my sample code is

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)
2
  • what is inside preimages folder? Commented May 14, 2016 at 4:44
  • @Ceem Only images.I have some random images of animals and buildings downloaded from google. Commented May 14, 2016 at 4:46

1 Answer 1

1

The problem is with your image set.Since you have downloaded images randomly from google.It may have different sizes and that is causing the Error.Before calling hog function you must resize the image.In opencv you can resize using

resized=cv2.resize(img,(250,250))
h=hog(resized)

In PIL library you can resize using

resolutin=(250.250)
resizes=img.resize(resolution , Image.ANTIALIAS)

But i must recommend to add a separate preproceesing step.In the preprocessing step you can resize and save all images in your 'preimages' folder to another folder and you can give this as input to your hog extraction program.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.