Reputation: 77
I am new in the domain of LibSVM and openCV and facing difficulties in coding correctly. I have generated LibSVM model using command prompt. Now I have file "myData.model". Now I want to use this model to predict instances through openCV.
Could you please let me know how to call model file in openCV project and how to pass instances to it one by one?
As per libSVM readme, this should be like:
Function: double svm_predict(const struct svm_model *model,
const struct svm_node *x);
But I am unable to understand how to make svm_node *x? I have instances in the same format as I extracted for training model i.e. label ....
Please do give me sample code to solve my problem.
Thanks in advance.
Upvotes: 1
Views: 2047
Reputation: 1321
you have to load your model and create the svm_node :
struct svm_model *SVMModel;
if ((SVMModel = svm_load_model(MODEL_FILE)) == 0) {
fprintf(stderr, "Can't load SVM model %s", MODEL_FILE);
return -2;
}
struct svm_node *svmVec;
svmVec = (struct svm_node *)malloc((dataMat.cols+1)*sizeof(struct svm_node));
double *predictions = new double[dataMat.rows];
You can find a full example here:
http://kuantinglai.blogspot.co.at/2013/07/using-libsvm-with-opencv-mat.html
Upvotes: 2