From 28c2d3b89ff3ada3188c2d5b856962fda1b0445b Mon Sep 17 00:00:00 2001 From: Vincent Rabaud Date: Sun, 13 Mar 2011 00:31:17 +0000 Subject: [PATCH] - replace the linear search in a sorted list by the appropriate algorithm --- modules/features2d/src/matchers.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/modules/features2d/src/matchers.cpp b/modules/features2d/src/matchers.cpp index f2a868d..e363c71 100755 --- a/modules/features2d/src/matchers.cpp +++ b/modules/features2d/src/matchers.cpp @@ -159,18 +159,11 @@ const Mat DescriptorMatcher::DescriptorCollection::getDescriptor( int globalDesc void DescriptorMatcher::DescriptorCollection::getLocalIdx( int globalDescIdx, int& imgIdx, int& localDescIdx ) const { - imgIdx = -1; - CV_Assert( globalDescIdx < size() ); - for( size_t i = 1; i < startIdxs.size(); i++ ) - { - if( globalDescIdx < startIdxs[i] ) - { - imgIdx = (int)(i - 1); - break; - } - } - imgIdx = imgIdx == -1 ? (int)(startIdxs.size() - 1) : imgIdx; - localDescIdx = globalDescIdx - startIdxs[imgIdx]; + CV_Assert( (globalDescIdx>=0) && (globalDescIdx < size()) ); + std::vector::const_iterator img_it = std::upper_bound(startIdxs.begin(), startIdxs.end(), globalDescIdx); + --img_it; + imgIdx = img_it - startIdxs.begin(); + localDescIdx = globalDescIdx - (*img_it); } int DescriptorMatcher::DescriptorCollection::size() const -- 2.7.4