我在这里有以下代码。我想问的是为什么opencv SVM预测2次训练后相同的对象结果是不同的?有任何解决方案可以结合2次训练结果吗?任何建议将被认真考虑。抱歉我的英语不好。
int main(int argc, char **argv){
// Set up SVM's parameters
CvSVMParams params;
params.svm_type = CvSVM::C_SVC;
params.kernel_type = CvSVM::LINEAR;
params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);
CvSVM SVM;
int idx, idx2;
// Set up test sample
Mat test = Mat(1, 2, CV_32FC1);
test.at<float>(0,0) = 1;
test.at<float>(0,1) = 1;
// Set up 1st training data
float labels[4] = {0, 1, 2, 3};
Mat labelsMat(4, 1, CV_32FC1, labels);
float trainingData[4][2] = { {0, 0}, {1, 1}, {2, 2}, {3, 3} };
Mat trainingDataMat(4, 2, CV_32FC1, trainingData);
SVM.train(trainingDataMat, labelsMat, Mat(), Mat(), params);
// Predict sample
idx = SVM.predict(test);
// Set up 2nd training data
float labels2[4] = {4, 5, 6, 7};
Mat labelsMat2(4, 1, CV_32FC1, labels);
float trainingData2[4][2] = { {4, 4}, {5, 5}, {6, 6}, {7, 7} };
Mat trainingDataMat2(4, 2, CV_32FC1, trainingData2);
SVM.train(trainingDataMat2, labelsMat2, Mat(), Mat(), params);
// Predict sample
idx2 = SVM.predict(test);
printf("idx [%d] idx2 [%d]\n", idx, idx2);
waitKey(0);
return 1;
}
以上代码输出为idx [1] idx2 [0]。为什么?