From ffbc2af731a1c424cc8dff9e51d3774f77b01ee0 Mon Sep 17 00:00:00 2001 From: Troels Ynddal Date: Mon, 5 Feb 2024 09:27:14 +0100 Subject: [PATCH 1/2] Increment pointers in `brute_force_matcher` when no match is found --- modules/cudafeatures2d/src/brute_force_matcher.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/cudafeatures2d/src/brute_force_matcher.cpp b/modules/cudafeatures2d/src/brute_force_matcher.cpp index 87316846d55..de2e29ff63f 100644 --- a/modules/cudafeatures2d/src/brute_force_matcher.cpp +++ b/modules/cudafeatures2d/src/brute_force_matcher.cpp @@ -791,8 +791,13 @@ namespace for (int i = 0; i < k; ++i) { const int trainIdx = *trainIdxPtr; - if (trainIdx == -1) + if (trainIdx == -1){ + ++trainIdxPtr; + ++distancePtr; + if (imgIdxPtr) + ++imgIdxPtr; continue; + } const int imgIdx = imgIdxPtr ? *imgIdxPtr : 0; const float distance = *distancePtr; From 5f50789c62b7e42099edc655002f496e4a66e8fb Mon Sep 17 00:00:00 2001 From: Troels Ynddal Date: Mon, 5 Feb 2024 13:45:15 +0100 Subject: [PATCH 2/2] Moved pointer increment for readability --- .../src/brute_force_matcher.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/modules/cudafeatures2d/src/brute_force_matcher.cpp b/modules/cudafeatures2d/src/brute_force_matcher.cpp index de2e29ff63f..d6e4618d6fb 100644 --- a/modules/cudafeatures2d/src/brute_force_matcher.cpp +++ b/modules/cudafeatures2d/src/brute_force_matcher.cpp @@ -791,21 +791,14 @@ namespace for (int i = 0; i < k; ++i) { const int trainIdx = *trainIdxPtr; - if (trainIdx == -1){ - ++trainIdxPtr; - ++distancePtr; - if (imgIdxPtr) - ++imgIdxPtr; - continue; + if (trainIdx != -1) + { + const int imgIdx = imgIdxPtr ? *imgIdxPtr : 0; + const float distance = *distancePtr; + DMatch m(queryIdx, trainIdx, imgIdx, distance); + curMatches.push_back(m); } - const int imgIdx = imgIdxPtr ? *imgIdxPtr : 0; - const float distance = *distancePtr; - - DMatch m(queryIdx, trainIdx, imgIdx, distance); - - curMatches.push_back(m); - ++trainIdxPtr; ++distancePtr; if (imgIdxPtr)