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 );