BlindChicken
BlindChicken

Reputation: 71

OpenCV SVM::predict() results set always gives same last value

Create Mat for output of predict function

    Mat results = Mat::zeros(200,1,CV_32FC1);  

Give predict function the features set and the results Mat I want the class labels returned in.

    svm.predict(features,results);  

Then the last (or 200th in this case) class label in the results mat will ALWAYS give the same weird number.

    qDebug() << k<<":" << results.at<float>(200)

200 : 1.4013e-45

svm was trained with classes 1 and -1. The rest of the class labels are returned correctly all of them accurate also. No matter the size of the results set or training set I get this weird last class label.

Upvotes: 1

Views: 693

Answers (1)

chappjc
chappjc

Reputation: 30579

0-based indexing. The last value in an array of 200 elements is the 199th element. With at<float>(200) you are reading junk memory past the end of the array.

Upvotes: 1

Related Questions