私はいくつかのOpenCVキーポイントを持っています、そしてそれらはvector<KeyPoint>
またはとして保存されlist<KeyPoint>
ます。キーポイントの応答に従ってそれらをソートして、最良のn個のキーポイントを取得するにはどうすればよいですか?
よろしく。
ドキュメントを見て、あなたがこのようなことをしようとしていると推測すると、
KeyPointがOpenCVでどのように実装されているかを次に示します。
だから私が理解していることから、あなたが使いたいのは応答要素です:
float response; // the response by which the most strong keypoints have been selected. Can be used for the further sorting or subsampling
したがって、これは間違いなく私があなたの場合にしようとしていることです. ベクトルを応答でソートする関数を作成します:)
お役に立てれば
編集:
Adrian のアドバイスを利用しようとしています (ただし、これは私の最初の cpp コードなので、実行する修正がいくつかあることを期待してください)
// 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;
}
キーポイントを次のように保存し、std::vector<cv::KeyPoint>
次のように並べ替えました。
std::sort(keypoints.begin(), keypoints.end(), [](cv::KeyPoint a, cv::KeyPoint b) { return a.response > b.response; });
注: ラムダ式には C++ 11 の使用が必要です。
キーポイントをベクトルに格納する場合:
#include <algorithm> // std::sort
#include <vector> // std::vector
int main() {
std::vector<KeyPoint> keypoints;
// extract keypoints right here
std::sort(keypoints.begin(), keypoints.end(), response_comparator);
// do what ever you want with keypoints which sorted by response
}
bool response_comparator(const KeyPoint& p1, const KeyPoint& p2) {
return p1.response > p2.response;
}