I'm trying to use OpenCV SVM with Hog descriptors. Working fine on a first sample with Python 2.7. When trying on an other example on python 3.6.1, i'm getting the following error :
error: /usr/local/src/opencv/modules/objdetect/src/hog.cpp:241: error: (-215) img.type() == CV_8U || img.type() == CV_8UC3 in function computeGradient
Here is a bunch of the code :
print('Defining HoG parameters ...')
print (np.array(digits_deskewed).shape)
print(digits_deskewed[0])
# HoG feature descriptor
hog = get_hog();
hog.compute(np.array(digits_deskewed[0]))
Gives this output :
(42000, 28, 28) [[ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 188. 255. 94. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
With get_hog() as :
def get_hog() :
winSize = (28,28)
blockSize = (4,4)
blockStride = (4,4)
cellSize = (8,8)
nbins = 9
derivAperture = 1
winSigma = -1.
histogramNormType = 0
L2HysThreshold = 0.2
gammaCorrection = 1
nlevels = 64
signedGradient = True
hog = cv2.HOGDescriptor(winSize,blockSize,blockStride,cellSize,nbins,derivAperture,winSigma,histogramNormType,L2HysThreshold,gammaCorrection,nlevels, signedGradient)
return hog
I have no idea of the reason of this error, can someone give me a clue ?
Thanks !
you have float type in your numpy array. you need uint8.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.