Skip to content

Commit

Permalink
fix: provide a sortMatch convenience function
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanchristopheruel committed Aug 22, 2024
1 parent 1c758fc commit 66783ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions modules/matching/include/openfdcm/matching/matchstrategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ namespace openfdcm::matching

inline bool operator<(const Match& lhs, const Match& rhs) noexcept{ return lhs.score < rhs.score; }

inline void sortMatches(std::vector<Match>& matches) {
std::sort(std::begin(matches), std::end(matches));
}

inline void sortMatches(std::vector<Match>& matches, size_t maxNumCandidates) {
std::partial_sort(std::begin(matches), std::begin(matches) +
std::min(maxNumCandidates, matches.size()), std::end(matches));
}

// ************************************************************************************************************
// Concepts
// ************************************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion tests/matching/src/matchstrategy.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void run_test(float scene_ratio, BS::concurrency_t num_threads) {
LineArray scene = transform(tmpl, scene_transform);
const Dt3Cpu& featuremap = buildCpuFeaturemap(scene, Dt3CpuParameters{depth, coeff, scene_padding}, threadpool);
auto matches = search(matcher, searchStrategy, optimizerStrategy, featuremap, {tmpl}, scene);
std::sort(std::begin(matches), std::end(matches));
sortMatches(matches);

Mat22 best_match_rotation = matches[0].transform.block<2, 2>(0, 0);
Point2 best_match_translation = matches[0].transform.block<2, 1>(0, 2);
Expand Down

0 comments on commit 66783ab

Please sign in to comment.