What is the best way to find the most frequent element of flann matrix such as flann::Matrix<int> k_indices
I propose that you to declare a map<int,int> counters
, then insert each element of your Matrix into the map and if the element already exist just increment the relative counter:
map<int,int> counters;
...
if(counters.count(yourNumber)==0)
counters[yourNumber] = 1
else
counters[yourNumber]++
and after get the counter of last element:
return counters.rbegin()->second;
I hope it helps!