diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index c7c91a1f7d..47883c46c3 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -2151,14 +2151,14 @@ inline void BruteForceMatcher::commonKnnMatchImpl( BruteForceMatcher::max(); for( size_t iIdx = 0; iIdx < imgCount; iIdx++ ) { - if( !allDists[iIdx].empty() ) - { - double minVal; - Point minLoc; - minMaxLoc( allDists[iIdx], &minVal, 0, &minLoc, 0 ); - if( minVal < bestMatch.distance ) - bestMatch = DMatch( qIdx, minLoc.x, (int)iIdx, (float)minVal ); - } + if( !allDists[iIdx].empty() ) + { + double minVal; + Point minLoc; + minMaxLoc( allDists[iIdx], &minVal, 0, &minLoc, 0 ); + if( minVal < bestMatch.distance ) + bestMatch = DMatch( qIdx, minLoc.x, (int)iIdx, (float)minVal ); + } } if( bestMatch.trainIdx == -1 ) break; diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 2bc4cedcd9..825ce2da55 100755 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -407,7 +407,7 @@ void BruteForceMatcher >::knnMatchImpl( const Mat& queryDescriptors, v for( int c = 0; c < masks[iIdx].cols; c++ ) { if( maskPtr[c] == 0 ) - e_allDists[iIdx](c) = std::numeric_limits::min(); + e_allDists[iIdx](c) = -std::numeric_limits::max(); } } } @@ -417,7 +417,7 @@ void BruteForceMatcher >::knnMatchImpl( const Mat& queryDescriptors, v vector >::reverse_iterator curMatches = matches.rbegin(); for( int k = 0; k < knn; k++ ) { - float totalMaxCoeff = std::numeric_limits::min(); + float totalMaxCoeff = -std::numeric_limits::max(); int bestTrainIdx = -1, bestImgIdx = -1; for( size_t iIdx = 0; iIdx < imgCount; iIdx++ ) { @@ -433,7 +433,7 @@ void BruteForceMatcher >::knnMatchImpl( const Mat& queryDescriptors, v if( bestTrainIdx == -1 ) break; - e_allDists[bestImgIdx](bestTrainIdx) = std::numeric_limits::min(); + e_allDists[bestImgIdx](bestTrainIdx) = -std::numeric_limits::max(); curMatches->push_back( DMatch(qIdx, bestTrainIdx, bestImgIdx, sqrt((-2)*totalMaxCoeff + queryNorm2)) ); } std::sort( curMatches->begin(), curMatches->end() ); @@ -1105,20 +1105,21 @@ void FernDescriptorMatcher::knnMatchImpl( const Mat& queryImage, vector::min(); + signature[best_ci] = -std:numeric_limits::max(); matches[queryIdx].push_back( bestMatch ); } }