I've some OpenCV KeyPoints, and they are stored as vector<KeyPoint>
or list<KeyPoint>
.
How to sort them according to the response of the KeyPoints to obtain the best n keypoints?
Regards.
Looking at the documentation, and guessing you are trying to do something like this,
Here is how KeyPoint is implemented in OpenCV.
So from what I understand, what you want to use is the response element:
float response; // the response by which the most strong keypoints have been selected. Can be used for the further sorting or subsampling
So this is definitely what I would be going to in your case. Create a function that sorts your vector by response :)
Hope this helps
EDIT:
Trying to take advantage of Adrian's advice (This is my first cpp code though, so expect to have some corrections to perform)
// list::sort
#include <list>
#include <cctype>
using namespace std;
// response comparison, for list sorting
bool compare_response(KeyPoints first, KeyPoints second)
{
if (first.response < second.response) return true;
else return false;
}
int main ()
{
list<KeyPoints> mylist;
list<KeyPoints>::iterator it;
// opencv code that fills up my list
mylist.sort(compare_response);
return 0;
}
I've stored the keypoints as std::vector<cv::KeyPoint>
and sorted them with:
std::sort(keypoints.begin(), keypoints.end(), [](cv::KeyPoint a, cv::KeyPoint b) { return a.response > b.response; });
Note: Usage of C++ 11 required for lambda-expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With