rror:'class cv :: ml :: TrainData'没有名为'getTestSamples'的成员Mat vdata = tdata-> getTestSamples();

时间:2017-01-03 10:30:19

标签: c++ opencv3.0 opencv3.1

使用ml,opencv 3.1

时出现此错误
: error: ‘class cv::ml::TrainData’ has no member named ‘getTestSamples’
 Mat vdata = tdata->getTestSamples();
                    ^

这可能是造成此错误的原因?

这是我的ml代码:

我已将这些内容纳入我的代码

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include "opencv2/imgcodecs.hpp"
#include <opencv2/highgui.hpp>
#include <opencv2/ml.hpp>

using namespace cv;
using namespace std;
using namespace cv::ml;




Ptr<ml::SVM> svm = ml::SVM::create();
Ptr<ml::TrainData> tdata = ml::TrainData::loadFromCSV("ear.csv",0,0,1);
tdata->setTrainTestSplitRatio(0.8);

Mat data = tdata->getTrainSamples();
Mat labels = tdata->getTrainResponses();
labels.convertTo(labels, CV_32S); 
svm->train(data,0,labels);

Mat vdata = tdata->getTestSamples();
Mat vlabels = tdata->getTestResponses();
Mat results;
svm->predict(vdata,results);

1 个答案:

答案 0 :(得分:0)

您使用的3.1版本中是否真的是opencv?

查看TrainData的文档,我实际上看不到您在公共界面中寻找的方法。有getTestSampleIdxgetTestSampleWeights,但不是您要呼叫的那个。