0

I'm tryint to build an application that classifies different objects. I have a training folder with a bunch of images i want to use as training for my SVM. Up untill now I have followed this (GREAT) answer: using OpenCV and SVM with images

here is a sample of my code:

def getTrainingData():

address = "..//data//training"
labels = []
trainingData = []
for items in os.listdir(address):
    ## extracts labels
    name = address + "//" + items
    for it in os.listdir(name):
        path = name + "//" + it
        print path
        img = cv.imread(path, cv.CV_LOAD_IMAGE_GRAYSCALE)
        d = np.array(img, dtype = np.float32)
        q = d.flatten()
        trainingData.append(q)
        labels.append(items)
        ######DEBUG######

        #cv.namedWindow(path,cv.WINDOW_NORMAL)
        #cv.imshow(path,img)

return trainingData, labels


svm_params = dict( kernel_type = cv.SVM_LINEAR,
                    svm_type = cv.SVM_C_SVC,
                    C=2.67, gamma=3 )

training, labels = getTrainingData()

train = np.asarray(training)
svm = cv.SVM()
svm.train(train, labels, params=svm_params)
svm.save('svm_data.dat')

But when i try to run i recieve the following error:

   svm.train(train, labels, params=svm_params)
TypeError: trainData data type = 17 is not supported

What am i doing wrong? Thanks A lot!

Community
  • 1
  • 1
Nimrodshn
  • 859
  • 3
  • 13
  • 29
  • have you had any luck with this? – Joe Minichino May 20 '15 at 20:29
  • 1
    @JoeMinichino. actoually iI have - I've simply moved all the learning to scikit learn and since then my life has been nothing but wonderfull. the parts that are done in openCV are preprocessing and feature extraction. In my experience scikit is a more flexible and pwoerfull learning library. Good Luck. – Nimrodshn May 22 '15 at 04:37
  • I actually agree with you - but i have some constrained to using cv2 for ML too. Have you any code you can share just in case i do manage to make my case and move over to sklearn? If you can of course. – Joe Minichino May 22 '15 at 12:43

1 Answers1

0

You should resize your input images. like this:

img = cv2.resize(img, (64,64))

Size is up to you.