diff --git a/modules/matching/include/openfdcm/matching/matchstrategy.h b/modules/matching/include/openfdcm/matching/matchstrategy.h index 2c0a2a0..b503f64 100644 --- a/modules/matching/include/openfdcm/matching/matchstrategy.h +++ b/modules/matching/include/openfdcm/matching/matchstrategy.h @@ -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& matches) { + std::sort(std::begin(matches), std::end(matches)); + } + + inline void sortMatches(std::vector& matches, size_t maxNumCandidates) { + std::partial_sort(std::begin(matches), std::begin(matches) + + std::min(maxNumCandidates, matches.size()), std::end(matches)); + } + // ************************************************************************************************************ // Concepts // ************************************************************************************************************ diff --git a/tests/matching/src/matchstrategy.test.cpp b/tests/matching/src/matchstrategy.test.cpp index d9f504a..1509452 100644 --- a/tests/matching/src/matchstrategy.test.cpp +++ b/tests/matching/src/matchstrategy.test.cpp @@ -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);