CV2:预处理机器学习的图像

时间:2014-07-19 18:17:51

标签: python-2.7 opencv

我打算用opencv2机器学习库创建svm来处理一些图像。我已经在这个网站上做了一些挖掘,我发现我需要将图像转换为矢量并从这些矢量中创建一个矩阵。但是我没有找到如何做到这一点的信息。请帮忙。请注意,我不是在使用python

1 个答案:

答案 0 :(得分:0)

可能所有opencv ml algos都需要以下输入:

  • a NxM trainData (float)Mat,其组成如下:
    • 每个要素一行(N),其中要素尺寸为M
  • Nx1标签数组(类ID),其中每个项目是索引i处相应要素的标签

所以,如果你有很多1d,扁平的功能和相应的标签,你会:

# 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)

look here,请!