Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

opencv's SVM can handle multi-class problems, it will make an one-vs-all problem for each class from it internally .

i can't give you python code (c++ person here), but you have to flatten each of your features to a single row, and stack them vertically into a single numpy array, so it looks like this:

FEATURES                       LABELS

feature1                          5
feature2                          3
feature3                          1
...

the features need to be a float32 numpy array, and te labels an int32 1xN numpy, then you can train your SVM:

svm = cv2.ml.SVM_create()
svm.train(features, cv2.ml.ROW_DATA, labels)

later you can predict on test features, reshaped in the same way to a single row:

predicted = svm.predict(feature)

opencv's SVM can handle multi-class problems, it will make an one-vs-all problem for each class from it internally .

i can't give you python code (c++ person here), but you have to flatten each of your features to a single row, and stack them vertically into a single numpy array, so it looks like this:

FEATURES                       LABELS

feature1                          5
feature2                          3
feature3                          1
...

the features need to be a float32 numpy array, and te the labels an int32 1xN numpy, numpy array, then you can train your SVM:

svm = cv2.ml.SVM_create()
svm.train(features, cv2.ml.ROW_DATA, labels)

later you can predict on test features, reshaped and converted in the same way to a single row:

predicted = svm.predict(feature)