繁体   English   中英

Opencv 3.0 SVM火车分类问题

[英]Opencv 3.0 SVM train classification issues

我是openCV SVM的新手。 我在Xcode 7.0,openCV 3.0中运行,下面是我的代码

MatMat labels(0,1,CV_32FC1);
//Mat labels(0,1,CV_32S);  //I also try this when i saw some posting, But error too.
...
Mat samples_32f; samples.convertTo(samples_32f, CV_32F);
//Mat samples_32f; samples.convertTo(samples_32f, CV_32FC1); //tried!

Ptr<SVM> classifier = SVM::create();
classifier->SVM::train(samples_32f, 0, labels);  <- Here the Error

OpenCV错误:错误参数(在分类问题中,响应必须是分类的;在创建TrainData时指定varType,或传递整数响应)在train中。

当我搜索一些解决方案时,错误消息似乎来自定义非整数值的labels 所以我不得不尝试更改为Mat labels(0,1,CV_32S) ,但是问题错误仍然相同。

所以我不知道代码出了什么问题..有人可以帮助吗?

错误是因为标签不包含定义为0行且每行1列的任何值。 因此,确保labels具有用于SVM训练的行数记录是正确的。

我的解决方案:

Mat labels(0,1,CV_32S); 

/*
for loop to use pushback added value into lables
{...}
*/
/*
or
define another Mat labeled(labels.rows, 1, CV_32S); after the for loop 
and use it in the SVM.train
*/

Mat samples_32f; samples.convertTo(samples_32f, CV_32F);

Ptr<SVM> classifier = SVM::create();
classifier->SVM::train(samples_32f, 0, labels);  <-change the labels names if you define new labels after the for loop.

谢谢,这就是我可以分享的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM