From 0ad1d0afacaa8c7d2db7206c7c92bb66f2156b4e Mon Sep 17 00:00:00 2001 From: Alexander Mordvintsev Date: Thu, 22 Sep 2011 08:52:40 +0000 Subject: [PATCH] fixed problem with incorrect distance values returned by FlannBasedMatcher for hamming metric (int's were interpreted as floats) --- modules/features2d/src/matchers.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index 2a6c66885c..e1c73a0bd5 100755 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -803,7 +803,12 @@ void FlannBasedMatcher::convertToDMatches( const DescriptorCollection& collectio { int imgIdx, trainIdx; collection.getLocalIdx( idx, imgIdx, trainIdx ); - matches[i].push_back( DMatch( i, trainIdx, imgIdx, std::sqrt(dists.at(i,j))) ); + float dist = 0; + if (dists.type() == CV_32S) + dist = static_cast( dists.at(i,j) ); + else + dist = std::sqrt(dists.at(i,j)); + matches[i].push_back( DMatch( i, trainIdx, imgIdx, dist ) ); } } }