I am facing problem in the hog.setSVMDetector(). I get the following error:
OpenCV Error: Assertion failed (checkDetectorSize()) in setSVMDetector
I have searched for this problem, and found out the winsize in the input arguments must be the same. I have used the same parameters for both training and testing. However I still get the same error.
Here is the code below:
####TESITNG
hog = cv2.HOGDescriptor((64,64), (16,16), (8,8), (8,8), 9) svm = cv2.SVM() svm.load('trained.xml')
img = cv2.imread('t_.png', cv2.IMREAD_GRAYSCALE) h = hog.compute(img) p = svm.predict(h) print p
model = pickle.load(open("svm.pickle")) hog.setSVMDetector(np.array(model))
######## HOG FEATURES COMPUTING METHOD
train_list = [] response_list = []
hog = cv2.HOGDescriptor((64,64), (16,16), (8,8), (8,8), 9) hog = cv2.HOGDescriptor() for i in range(2,23): img = cv2.imread('/home/taseer/Python/Image_Processing/Project/resized/' + str(i) + "_.png", cv2.IMREAD_COLOR) h = hog.compute(img) h = h.ravel() train_list.append(h)
if i > 7:
response_list.append(1)
else:
response_list.append(-1)
model = cv2.SVM() model.train(np.array(train_list), np.array(response_list)) model.save('trained.xml')
I also found that the winsize must be equal to the size of images. I have resized all my images to (150,150).
for i in range(1,17): img = Image.open('/home/taseer/Python/Image_Processing/Project/positive/pos/' + str(i) + ".jpg") r = img.resize((150,150)) r.save('/home/taseer/Python/Image_Processing/Project/resized/' + str(i+7) + '_.png')