OpenCV 2.3 RC Python SVM: TypeError: <unknown> is not a numpy array
Hello,
I am trying to use the new cv2 SVM (Support Vector Machine) Python binding in OpenCV 2.3 RC. I compiled OpenCV from source under Ubuntu 10.04 and as soon as I execute this function:
svm = cv2.SVM(training_data, responses)
I get the error:
TypeError: <unknown> is not a numpy array
Does anyone know what I am doing wrong or how to fix this?
Here is the full function I am using to train the SVM. The variables self.positive_samples and self.negative_samples are Python lists of SURF feature vectors (64 elements long). The variable self.classes is a Python list of 1's and -1's indicating the class a sample belongs to.
def init_classifier(self):
n_positive_samples = len(self.positive_samples)
n_negative_samples = len(self.negative_samples)
n_samples = n_positive_samples + n_negative_samples
training_data = cv.CreateMat(n_samples, 64, cv.CV_32FC1)
responses = cv.CreateMat(n_samples, 1, cv.CV_32FC1)
for i in range(n_positive_samples):
cv.Set2D(responses, i, 0, self.classes[i])
for j in range(64):
cv.Set2D(training_data, i, j, self.positive_samples[i][j])
for i in range(n_positive_samples, n_samples):
i_negative = i - n_positive_samples
cv.Set2D(responses, i, 0, self.classes[i_negative])
for j in range(64):
cv.Set2D(training_data, i, j, self.negative_samples[i_negative][j])
svm = cv2.SVM(training_data, responses)