SVMDetector

asked 2016-03-27 12:56:08 -0500

Taseer gravatar image

updated 2016-03-29 04:31:09 -0500

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:

TESTING

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')
edit retag flag offensive close merge delete

Comments

Please in the future, use the 101010 button to format your code to get a more visible and clear view on the problem ;)

StevenPuttemans gravatar imageStevenPuttemans ( 2016-03-29 04:31:53 -0500 )edit

OK thanks :-)

Taseer gravatar imageTaseer ( 2016-03-29 10:21:48 -0500 )edit