Recently, I want to use SVM to output the Top N matching results. After reading SVM and predict in opencv, we can only output top 1.
Three predict functions are available. One of them uses CV: parallel_for, which should be parallel optimization and cannot be found in the relevant explanatory documents.
Last selected
Float cvsvm: predict (const float * row_sample, int row_len, bool returndfval) const
Returndfval does not work if it is not a one-class problem.
In fact, there is no choice, because the other few are based on this ....
The original Code contains the following content, which is the maximum output value. Sort and then output the nth value.
For (I = 1, K = 0; I <class_count; I ++)
{
If (vote [I]> vote [k])
K = I;
}
Result = returndfval & class_count = 2? (Float) sum: (float) (class_labels-> data. I [k]);
}
Else
Cv_error (cv_stsbadarg, "internal error: Unknown SVM type ,"
"The SVM structure is probably successfully upted ");
Return result;
}
If you do not change the source code, you need to train (N * N-1)/Two SVM, then set returndfval to true, and compare the output results by yourself.
The last modification is as follows:
/*
For (I = 1, K = 0; I <class_count; I ++)
{
If (vote [I]> vote [k])
K = I;
}
Result = returndfval & class_count = 2? (Float) sum: (float) (class_labels-> data. I [k]);
*/
/* Modify the code so that the nth number can be output as a candidate result */
Float xx = 0;
CV: mat vote2 = CV: MAT (class_count, 1, cv_32fc1, vote );
CV: mat vote3;
CV: sortidx (vote2, vote3, cv_sort_every_column + cv_sort_descending );
K = vote3.at <int> (n-1, 0 );
Result = returndfval & class_count = 2? (Float) sum: (float) (class_labels-> data. I [k]);
The results are to be verified.
After changing the HPP and CPP, check whether the HPP has been referenced. If it is different from the referenced one, it will be a tragedy. Then I met it. I thought about it right away when I had a good rest.