Fix trees parsing behavior in hierarchical_clustering_index:
authorPierre-Emmanuel Viel <p.emmanuel.viel@gmail.com>
Thu, 18 Jun 2020 14:30:29 +0000 (16:30 +0200)
committerPierre-Emmanuel Viel <p.emmanuel.viel@gmail.com>
Thu, 2 Jul 2020 23:19:10 +0000 (01:19 +0200)
Before, when maxCheck was reached in the first descent of a tree, time was still wasted parsing
the next trees till their best leaves whose points were not used at all.

modules/flann/include/opencv2/flann/hierarchical_clustering_index.h

index d830bc6a00ee76ef7e7cc0511a68bc0b858d1788..2937509924399ea2b3c1be25a192ad43df885305 100644 (file)
@@ -548,7 +548,7 @@ public:
     void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE
     {
 
-        int maxChecks = get_param(searchParams,"checks",32);
+        const int maxChecks = get_param(searchParams,"checks",32);
 
         // Priority queue storing intermediate branches in the best-bin-first search
         Heap<BranchSt>* heap = new Heap<BranchSt>((int)size_);
@@ -557,6 +557,8 @@ public:
         int checks = 0;
         for (int i=0; i<trees_; ++i) {
             findNN(root[i], result, vec, checks, maxChecks, heap, checked);
+            if ((checks >= maxChecks) && result.full())
+                break;
         }
 
         BranchSt branch;
@@ -748,8 +750,8 @@ private:
                 Heap<BranchSt>* heap, std::vector<bool>& checked)
     {
         if (node->childs==NULL) {
-            if (checks>=maxChecks) {
-                if (result.full()) return;
+            if ((checks>=maxChecks) && result.full()) {
+                return;
             }
             for (int i=0; i<node->size; ++i) {
                 int index = node->indices[i];