如何在openCV项目中使用LIBSVM生成的模型 [英] How to use model generated by LIBSVM in openCV project

查看:437
本文介绍了如何在openCV项目中使用LIBSVM生成的模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是在LibSVM和openCV的领域的新的,并面临编码中的困难正确。我已经使用命令提示符生成LibSVM模型。现在我有文件myData.model。现在我想使用这个模型通过openCV预测实例。

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.

您能否让我知道如何在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?

根据libSVM自述文件,这应该像:

As per libSVM readme, this should be like:

 Function: double svm_predict(const struct svm_model *model,
                               const struct svm_node *x);

但我无法理解如何使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.

提前感谢。

推荐答案

并创建svm_node:

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

这篇关于如何在openCV项目中使用LIBSVM生成的模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆