aibrain
aibrain

Reputation: 11

Using HOG to get image descriptors but hog.compute always returns 0.0

64x64 image Trying to use OpenCV to do something simple in Python. Using HOG to get the feature vector. But I get all 0.0. I've tried a few images same result.

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)

Upvotes: 1

Views: 1400

Answers (1)

Shawn Mathew
Shawn Mathew

Reputation: 2337

Simply using hist = hog.compute(image) gives a non-zero result.

By default winstride, padding, locations are empty tuples. However, if you are firm on using winstride, etc your image is 64x64 and your window size (winsize) is 64x64, adding a 8x8 winstride will cause no overlapping of the window on the image, hence your output is filled with zeros.

To clarify, winsize is the size of the sliding window that is run across the entire image. Since the size of the image and the sliding window is the same, due to the manner in which HoG features are calculated, there will be no features created, which is why you're seeing zeros.

Upvotes: 1

Related Questions