Ask Your Question

Revision history [back]

ML - Exception in CvSVM::predict when using NU_SVC as type

I have some simple code, which works:

CvSVM svm;
CvSVMParams svmparams;
svmparams.svm_type = CvSVM::C_SVC;
svmparams.kernel_type = CvSVM::RBF;
svmparams.gamma = 1.0;
svmparams.coef0 = 0.0;
svmparams.C = 0.5; = 0.5;
... load the dataset
svm.train(trainIn, trainOut, 0, 0, svmparams);
for (int v = 0; v < validateIn->rows; v++) {
    cvGetRow(validateIn, &sample, v);
    cat = validateOut->data.fl[v];
    float r = 0.0;
    r = svm.predict(&sample);

My problem is that as soon as i set

svmparams.svm_type = CvSVM::NU_SVC;

i get the following runtime error:

OpenCV Error: Bad argument (The SVM should be trained first) in CvSVM::predict, file E:\Dev\new\opencv\modules\ml\src\svm.cpp, line 2129 terminate called after throwing an instance of 'cv::Exception' what(): E:\Dev\new\opencv\modules\ml\src\svm.cpp:2129: error: (-5) The SVM should be trained first in function CvSVM::predict

It seems as if it ignores the training when NU_SVC is set. Any ideas?