【问题标题】:Opencv 3.0 SVM train classification issuesOpencv 3.0 SVM 训练分类问题
【发布时间】:2016-01-22 12:20:41
【问题描述】:

我是 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,或传递整数响应)。

当我搜索一些解决方案时,错误消息似乎来自labels,它定义了非整数值。所以我尝试改成Mat labels(0,1,CV_32S),但是问题还是一样。

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

【问题讨论】:

    标签: c++ opencv svm


    【解决方案1】:

    错误是因为标签不包含定义为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.
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-05-04
      • 2015-07-25
      • 1970-01-01
      • 2015-04-18
      • 2015-01-22
      • 2017-08-25
      • 2015-09-26
      相关资源
      最近更新 更多