我在C ++中使用OpenCV 3.0.0来训练普通贝叶斯分类器。我训练了分类器,并将其存储到文件中。现在我试图使用分类器来预测响应。以下是相关代码:
Ptr<TrainData> trainingData = TrainData::loadFromCSV(trainingDataFile,0);
std::cout << "Training data has been loaded.\n";
Mat samples = trainingData->getTrainSamples();
Mat correctResponses = trainingData->getTrainResponses();
std::cout << "Loading NB classifier...\n";
Ptr<NormalBayesClassifier> nbClassifier = NormalBayesClassifier::load<NormalBayesClassifier>(trainingDataFile+"_trainedNBParams.dat");
std::cout << "NB classifier loaded.\n";
Mat receivedResponses;
std::cout << "Classifying data using NB classifier...\n";
nbClassifier->predict(samples,receivedResponses); //error here
std::cout << "Classification complete.\n";
我收到以下错误:
OpenCV Error: Null pointer (When the number of input samples is >1, the output vector of results must be passed) in predictProb, file /home/keyur/OpenCV/opencv-3.0.0/modules/ml/src/nbayes.cpp, line 318
terminate called after throwing an instance of 'cv::Exception'
what(): /home/keyur/OpenCV/opencv-3.0.0/modules/ml/src/nbayes.cpp:318: error: (-27) When the number of input samples is >1, the output vector of results must be passed in function predictProb
我不明白输出矩阵应该如何传递给函数。文档相当模糊,其他StackOverflow答案对这个特定问题没有多大帮助。
文档链接: http://docs.opencv.org/3.0.0/d4/d8e/classcv_1_1ml_1_1NormalBayesClassifier.html
答案 0 :(得分:0)
该错误是由OpenCV 3.0.0中的错误导致的,该错误已在OpenCV 3.1.0中修复。