4

I am using the code snippet given in here to compute HOG feature of a small image patch. However for the code attached herewith, the variable h, which is supposed to hold HOG feature values, is returning an empty tuple instead. Can anyone please point me to where am I going wrong in the code?

import numpy as np
import cv2

img = cv2.imread('newimg.jpg')
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_gray = cv2.resize(img_gray,(50,50))

hog = cv2.HOGDescriptor()
h = hog.compute(img_gray)
print(h)

The test image is attached here

Community
  • 1
  • 1
Geek
  • 395
  • 1
  • 9

1 Answers1

2

I think there is problem regarding the image size. More specifically image size is smaller as compare to the default window size of hog Descriptor. I recommend resize your image and then use the code snippet attached below.

winSize = (32,32)
blockSize = (16,16)
blockStride = (8,8)
cellSize = (8,8)
nbins = 9
hog = cv2.HOGDescriptor(winSize, blockSize, blockStride, cellSize, nbins)
h = hog.compute(img_gray)
print(h) 
Encipher
  • 1,370
  • 1
  • 14
  • 31