From 40c05d841831ae1c38c01c8924d83831346e7f34 Mon Sep 17 00:00:00 2001 From: Ethan Rublee Date: Mon, 1 Nov 2010 05:34:51 +0000 Subject: [PATCH] Brute force implementation had issues with the type of distances it was storing. Rectified this, hopefully. --- .../features2d/include/opencv2/features2d/features2d.hpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/features2d/include/opencv2/features2d/features2d.hpp b/modules/features2d/include/opencv2/features2d/features2d.hpp index a0d0c14454..12a61be76f 100644 --- a/modules/features2d/include/opencv2/features2d/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d/features2d.hpp @@ -1808,7 +1808,7 @@ inline void bfKnnMatchImpl( BruteForceMatcher& matcher, size_t imgCount = matcher.trainDescCollection.size(); vector allDists( imgCount ); // distances between one query descriptor and all train descriptors for( size_t i = 0; i < imgCount; i++ ) - allDists[i] = Mat( 1, matcher.trainDescCollection[i].rows, queryDescs.type() ); + allDists[i] = Mat( 1, matcher.trainDescCollection[i].rows, DataType::type ); for( int qIdx = 0; qIdx < queryDescs.rows; qIdx++ ) { @@ -1836,7 +1836,7 @@ inline void bfKnnMatchImpl( BruteForceMatcher& matcher, { const ValueType* d2 = (const ValueType*)(matcher.trainDescCollection[iIdx].data + matcher.trainDescCollection[iIdx].step*tIdx); - allDists[iIdx].at(0, tIdx) = matcher.distance(d1, d2, dimension); + allDists[iIdx].at(0, tIdx) = matcher.distance(d1, d2, dimension); } } } @@ -1847,6 +1847,7 @@ inline void bfKnnMatchImpl( BruteForceMatcher& matcher, for( int k = 0; k < knn; k++ ) { DMatch bestMatch; + bestMatch.distance = std::numeric_limits::max(); for( size_t iIdx = 0; iIdx < imgCount; iIdx++ ) { double minVal; @@ -1858,9 +1859,10 @@ inline void bfKnnMatchImpl( BruteForceMatcher& matcher, if( bestMatch.trainIdx == -1 ) break; - allDists[bestMatch.imgIdx].at(0, bestMatch.trainIdx) = std::numeric_limits::max(); + allDists[bestMatch.imgIdx].at(0, bestMatch.trainIdx) = std::numeric_limits::max(); curMatches->push_back( bestMatch ); } + //TODO should already be sorted at this point? std::sort( curMatches->begin(), curMatches->end() ); } }