Opencv 3.0 SVM火车分类问题 [英] Opencv 3.0 SVM train classification issues
问题描述
这是openCV SVM的新功能.我在Xcode 7.0,openCV 3.0中运行,下面是我的代码
Im new in openCV SVM. Im running in Xcode 7.0, openCV 3.0, Below is my code
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,或者传递整数响应).
The OpenCV Error: Bad argument (in the case of classification problem the responses must be categorical; either specify varType when creating TrainData, or pass integer responses) in train.
当我搜索一些解决方案时,错误消息似乎来自labels
,它们定义的不是整数值.因此,我不得不尝试更改为Mat labels(0,1,CV_32S)
,但是问题错误仍然相同.
When I search around some solutions, the error message seem was came from labels
that define not integer value. So i had try to changed to Mat labels(0,1,CV_32S)
, but the issues error still the same.
所以我不知道代码出了什么问题.有人可以帮忙吗?
So i have no idea what going wrong with the code..is anyone can help?
推荐答案
错误是因为标签不包含定义为0
行且具有1
列的任何值.因此,确保labels
具有用于SVM训练的保留行数记录是正确的.
The errors is because labels does not content any value as defined as 0
rows with 1
cols. Therefore, it is correct to make sure labels
has holding numbers of rows records for SVM training.
我的解决方案:
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.
谢谢,这就是我可以分享的.
Thanks, that's what i can share.
这篇关于Opencv 3.0 SVM火车分类问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!