Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

What mean is SVM predict method return value ?

I use predict method for 2-class classification with SVM labeled +1 or -1. And returnDFVal is false, then I get +1 or -1 accurate. but, returnDFVal is true, then return value is opposite to the label, i.e.

returnDFVal = false -> return = -1

returnDFVal = true  -> return = 1.07756

code is below, best regard.

float svmPredict(const char* classifier, const char* image, const char* method)
{
    // load query image
    cv::Mat img = cv::imread(image, CV_LOAD_IMAGE_GRAYSCALE);

    // compute descriptor for each keypoint
    cv::Mat desc;
    desc = getDescriptors(img, method);

    // load svm classifier
    cv::SVM svm;
    svm.load(classifier);

    // convert descriptor -> vector
    cv::Mat centroids(1, 64, CV_32F);
    cv::Mat label(1, 1, CV_32F, cv::Scalar(-1));
    cv::kmeans(desc, 1, label, cv::TermCriteria(CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 10, 1.0), 1, 2, centroids);

    // predict
    //float predict = svm.predict(centroids, false);
    float predict = svm.predict(centroids, true);

    return predict;
}