get the score from a multi-class SVM classifier using emgu cv and c#

750 Views Asked by At

hello I am working on person recognition, I would like to get the score for each tested sample (image) from a multi-class SVM classification. I am using c# and EmguCv. Any help will be appreciated.

1

There are 1 best solutions below

1
On

Only way - reduild OpenCV and get all votes from it. You can see it in file "svm.cpp". I add this code in predict function:

    bool Yes = false;
    if( _results.needed() )
    {
        _results.create(class_count+1, 1, samples.type());
        results = _results.getMat();
        Yes = true;
    }
    else
    {
        CV_Assert( nsamples == 1 );
        results = Mat(1, 1, CV_32F, &result);
    }

    PredictBody invoker(this, samples, results, returnDFVal);
    if( nsamples < 10 )
        invoker(Range(0, nsamples));
    else
        parallel_for_(Range(0, nsamples), invoker);
    if (Yes)
    {
        result = results.at<float>(class_count);
    }
    return result;

And this code in PredictBody

  if (results->cols + results->rows > 2)
    {
        for (int jk = 0; jk < class_count; jk++)
            results->at<float>(jk) = (float)vote[jk];
        results->at<float>(class_count) = result;
    }
    else
          results->at<float>(si) = result;

So, i take back all needed votes from opencv. But, as you can see from svm.cpp there is no normal way to do it.