From e9050395be369976e1c17e4ad06748b294291042 Mon Sep 17 00:00:00 2001 From: Yuan-Chu Tai Date: Fri, 5 Jan 2024 14:13:04 +0800 Subject: [PATCH 1/4] add maxconers and mindistance setter to gftt --- modules/cudaimgproc/include/opencv2/cudaimgproc.hpp | 3 +++ modules/cudaimgproc/src/gftt.cpp | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/cudaimgproc/include/opencv2/cudaimgproc.hpp b/modules/cudaimgproc/include/opencv2/cudaimgproc.hpp index 4c9ee0f48e8..00edfc19838 100644 --- a/modules/cudaimgproc/include/opencv2/cudaimgproc.hpp +++ b/modules/cudaimgproc/include/opencv2/cudaimgproc.hpp @@ -578,6 +578,9 @@ class CV_EXPORTS_W CornersDetector : public Algorithm @param stream Stream for the asynchronous version. */ CV_WRAP virtual void detect(InputArray image, OutputArray corners, InputArray mask = noArray(), Stream& stream = Stream::Null()) = 0; + + virtual void setMaxCorners(int maxCorners) = 0; + virtual void setMinDistance(double minDistance) = 0; }; /** @brief Creates implementation for cuda::CornersDetector . diff --git a/modules/cudaimgproc/src/gftt.cpp b/modules/cudaimgproc/src/gftt.cpp index 540534a87ab..2d3c51297b7 100644 --- a/modules/cudaimgproc/src/gftt.cpp +++ b/modules/cudaimgproc/src/gftt.cpp @@ -69,7 +69,8 @@ namespace int blockSize, bool useHarrisDetector, double harrisK); ~GoodFeaturesToTrackDetector(); void detect(InputArray image, OutputArray corners, InputArray mask, Stream& stream); - + void setMaxCorners(int maxCorners) CV_OVERRIDE { maxCorners_ = maxCorners; } + void setMinDistance(double minDistance) CV_OVERRIDE { minDistance_ = minDistance; } private: int maxCorners_; double qualityLevel_; From 0322b4621d43e1a9a8f02fc93a9cb0dee1c898bc Mon Sep 17 00:00:00 2001 From: zanaviska <31745527+zanaviska@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:52:42 +0000 Subject: [PATCH 2/4] Fix gcc11 warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ‘error’ may be used uninitialized --- modules/ximgproc/src/edge_drawing.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ximgproc/src/edge_drawing.cpp b/modules/ximgproc/src/edge_drawing.cpp index 4ff15324b70..fab94fc6336 100644 --- a/modules/ximgproc/src/edge_drawing.cpp +++ b/modules/ximgproc/src/edge_drawing.cpp @@ -1366,7 +1366,7 @@ void EdgeDrawingImpl::SplitSegment2Lines(double* x, double* y, int noPixels, int { // Start by fitting a line to MIN_LINE_LEN pixels bool valid = false; - double lastA(0), lastB(0), error; + double lastA(0), lastB(0), error(0); int lastInvert(0); while (noPixels >= min_line_len) From 17354903b29a56929d882414116ab007a3e4009a Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Thu, 1 Feb 2024 18:05:06 +0300 Subject: [PATCH 3/4] Wrap new methods to python and java. --- modules/cudaimgproc/include/opencv2/cudaimgproc.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/cudaimgproc/include/opencv2/cudaimgproc.hpp b/modules/cudaimgproc/include/opencv2/cudaimgproc.hpp index 00edfc19838..aab80799643 100644 --- a/modules/cudaimgproc/include/opencv2/cudaimgproc.hpp +++ b/modules/cudaimgproc/include/opencv2/cudaimgproc.hpp @@ -579,8 +579,8 @@ class CV_EXPORTS_W CornersDetector : public Algorithm */ CV_WRAP virtual void detect(InputArray image, OutputArray corners, InputArray mask = noArray(), Stream& stream = Stream::Null()) = 0; - virtual void setMaxCorners(int maxCorners) = 0; - virtual void setMinDistance(double minDistance) = 0; + CV_WRAP virtual void setMaxCorners(int maxCorners) = 0; + CV_WRAP virtual void setMinDistance(double minDistance) = 0; }; /** @brief Creates implementation for cuda::CornersDetector . From 48b5dedb0b2bd15f4e99e4b4da18a6d2f2561309 Mon Sep 17 00:00:00 2001 From: Troels Ynddal Date: Tue, 6 Feb 2024 15:53:36 +0100 Subject: [PATCH 4/4] Merge pull request #3632 from troelsy:4.x Fix a bug in knnMatchConvert when a feature couldn't be matched #3632 After I started using a mask with `knnMatchAsync`, I found that the result from `knnMatchConvert` would be clipped at random. Investigating the issue, I found that `knnMatchAsync` will initialize all `trainIdx` to `-1`, which will be overwritten by the CUDA kernel. A mask can be used to prevent certain features from being matched and this will prevent the CUDA kernel from setting the match distance. `knnMatchConvert` is not properly incrementing the pointers when `trainIdx == -1`, so an unmatched feature will get it stuck at `if (trainIdx == -1)`. Eventually the outer for-loop finishes and returns a vector with the matches up until the first missing match distance. My solution is to increment the counters the same way as a successful iteration would. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake --- .../cudafeatures2d/src/brute_force_matcher.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/cudafeatures2d/src/brute_force_matcher.cpp b/modules/cudafeatures2d/src/brute_force_matcher.cpp index 87316846d55..d6e4618d6fb 100644 --- a/modules/cudafeatures2d/src/brute_force_matcher.cpp +++ b/modules/cudafeatures2d/src/brute_force_matcher.cpp @@ -791,15 +791,13 @@ namespace for (int i = 0; i < k; ++i) { const int trainIdx = *trainIdxPtr; - if (trainIdx == -1) - continue; - - const int imgIdx = imgIdxPtr ? *imgIdxPtr : 0; - const float distance = *distancePtr; - - DMatch m(queryIdx, trainIdx, imgIdx, distance); - - curMatches.push_back(m); + if (trainIdx != -1) + { + const int imgIdx = imgIdxPtr ? *imgIdxPtr : 0; + const float distance = *distancePtr; + DMatch m(queryIdx, trainIdx, imgIdx, distance); + curMatches.push_back(m); + } ++trainIdxPtr; ++distancePtr;