0

I planning to create svm with opencv2 machine learning libraries to process some images. I have done some digging on this site and I have found I need to convert the images into vectors and create a matrix out of these vectors. However I have found no information how to do that. Please help. Please also not that I am using python

user2850408
  • 41
  • 2
  • 6

1 Answers1

0

probably all opencv ml algos want the following inputs:

  • a NxM trainData (float)Mat, that is composed like:
    • one row(N) per feature, where the feature size is M
  • a Nx1 array of labels(class ids) where each item is the label for the corresponding feature at index i

so, if you have a lot of 1d, flattened features, and corresponding labels you would:

# pseudocode
svm = cv2.SVM() # getting the params right is a science of its own..

traindata, trainlabels = [],[]
for i in (my trainig data ):
    traindata.extend(feature) # again, 1 flattened array of numbers
    trainlabels.append(label) # 1 class id for the feature above

# now train it:
svm.train(np.array(traindata), np.array(trainlabels))

# after that, we can go and predict labels from new test input,
# it will return the predicted label(same one you fed to the training before...)
p = svm.predict(test_feature)

also look here, please !

Community
  • 1
  • 1
berak
  • 39,159
  • 9
  • 91
  • 89