hi , i have trouble with predict hog image data with SVM
import cv2 import numpy as np
SZ=20 bin_n = 16 # Number of bins affine_flags = cv2.WARP_INVERSE_MAP|cv2.INTER_LINEAR 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_nang/(2np.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 svm=cv2.ml.SVM_load('svm_data.dat') // train data img=cv2.imread('test.jpg',1) test=hog(img) test1 = np.float32(test).reshape(-1,64) y=svm.predict(test1)
print y
results for any image gives below one
(0.0, array([[ 0.]], dtype=float32))