{
float *ratings;
float threshold;
float bestgap;
float gapstart;
BLOB_CHOICE_LIST_C_IT list_it = blob_choices;
BLOB_CHOICE_IT choice_it;
blob_count = blob_choices->length ();
ratings = (
float *)
alloc_mem (blob_count *
sizeof (
float));
for (list_it.mark_cycle_pt (), index = 0;
!list_it.cycled_list (); list_it.forward (), index++) {
choice_it.set_to_list (list_it.data ());
if (choice_it.length () > 0) {
ratings[ok_blob_count] = choice_it.data ()->certainty ();
ok_blob_count++;
}
}
qsort (ratings, ok_blob_count,
sizeof (
float),
sort_floats);
bestgap = 0;
gapstart = ratings[0] - 1;
if (ok_blob_count >= 3) {
for (index = 0; index < ok_blob_count - 1; index++) {
if (ratings[index + 1] - ratings[index] > bestgap) {
bestgap = ratings[index + 1] - ratings[index];
gapstart = ratings[index];
}
}
}
threshold = gapstart + bestgap / 2;
return threshold;
}