OK, let me give you some insights and useful links, but the answer remains the same: you can't get SVM multiclass probability with a pure combination of OpenCV functions and minimum effort.
OpenCV SVM (based on LibSVM) implements multi-class classification in the form of one-vs-one problems, i.e. each class is compared with each other class, so there is N(N-1)/2 decision functions in an N-class problem. Each comparison has a winner class, and such class receives one vote to be the final best match (so yeah, you obviously get the best match). This is coded in svm.cpp, lines 1886-1906:
for( i = dfi = 0; i < class_count; i++ )
{
for( j = i+1; j < class_count; j++, dfi++ )
{
const DecisionFunc& df = svm->decision_func[dfi];
sum = -df.rho;
int sv_count = svm->getSVCount(dfi);
const double* alpha = &svm->df_alpha[df.ofs];
const int* sv_index = &svm->df_index[df.ofs];
for( k = 0; k < sv_count; k++ )
sum += alpha[k]*buffer[sv_index[k]];
vote[sum > 0 ? i : j]++;
}
}
for( i = 1, k = 0; i < class_count; i++ )
{
if( vote[i] > vote[k] )
k = i;
}
Regarding probabilities, they're not so easy to compute. In fact, even for 2-class classification problems, no probability is outputted in OpenCV. Instead, we can just get the distance of the sample to the SVM separating hyperplane, which gives a rough indicator of the correctness of the prediction (the larger the distance, the larger the confidence). There are several methods to compute probabilities, and you can read about them in the LibSVM manual, Section 8.
The getDecisionFunction() indeed gives you all necesarry information to predict yourself the output value, but in any case you would have to implement a probability estimator, which I doubt is your goal here.
Afaik, there is no out-of-box way to get multiclass probability in OpenCV (it can be retrieved in a 2-class classification problem though)
Yeah, that is what I thought too, but then I found this post which got me thinking that it is. I could not find this line of code in the opencv 3.1 file mentioned but I DID find getDecisionFunction method. Im just not sure how to use it, its a bit over my head.
Im trying to detect multiple positions of one human in a video. Someone told me a multi class SVM is the way to go, and I have the code working, just doesn't give probability...so this method is moot if I can't get that. When I run the video it will classify the first 100 frames as "1" the next 100 as "2", and so forth. I just need the BEST match for each class that I train in the SVM.