- replace the linear search in a sorted list by the appropriate algorithm
authorVincent Rabaud <no@email>
Sun, 13 Mar 2011 00:31:17 +0000 (00:31 +0000)
committerVincent Rabaud <no@email>
Sun, 13 Mar 2011 00:31:17 +0000 (00:31 +0000)
modules/features2d/src/matchers.cpp

index f2a868d..e363c71 100755 (executable)
@@ -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<int>::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