From 73fc8ee93ee863b60a0c84e2f0f3010bab1c71b0 Mon Sep 17 00:00:00 2001 From: Shahnawaz Ahmed <44529331+shah-scalpel@users.noreply.github.com> Date: Mon, 20 Sep 2021 02:26:18 +0530 Subject: [PATCH] Update annf.hpp xphoto inpaint shiftmap kdtree crush fix https://github.com/opencv/opencv_contrib/issues/965#issuecomment-429534323 --- modules/xphoto/src/annf.hpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/xphoto/src/annf.hpp b/modules/xphoto/src/annf.hpp index 1534fa50acf..111469fe1d0 100644 --- a/modules/xphoto/src/annf.hpp +++ b/modules/xphoto/src/annf.hpp @@ -166,11 +166,13 @@ KDTree(const cv::Mat &img, const int _leafNumber, const int _zeroThresh) int dimIdx = getMaxSpreadN(_left, _right); KDTreeComparator comp( this, dimIdx ); + std::vector _idx(idx.begin(), idx.end()); std::nth_element(/**/ - idx.begin() + _left, - idx.begin() + nth, - idx.begin() + _right, comp + _idx.begin() + _left, + _idx.begin() + nth, + _idx.begin() + _right, comp /**/); + idx = _idx; left.push(_left); right.push(nth + 1); left.push(nth + 1); right.push(_right); @@ -280,11 +282,12 @@ static void dominantTransforms(const cv::Mat &img, std::vector &tr } } - std::partial_sort( amount.begin(), amount.begin() + nTransform, + int num = std::min((int)amount.size(), (int)nTransform); + std::partial_sort( amount.begin(), amount.begin() + num, amount.end(), std::greater< std::pair >() ); - transforms.resize(nTransform); - for (int i = 0; i < nTransform; ++i) + transforms.resize(num); + for (int i = 0; i < num; ++i) { int idx = amount[i].second; transforms[i] = cv::Point2i( shiftM[idx].x, shiftM[idx].y );