Skip to content

Commit 7286848

Browse files
committed
Fix trees parsing behavior in hierarchical_clustering_index:
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.
1 parent 73f7d09 commit 7286848

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
548548
void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE
549549
{
550550

551-
int maxChecks = get_param(searchParams,"checks",32);
551+
const int maxChecks = get_param(searchParams,"checks",32);
552552

553553
// Priority queue storing intermediate branches in the best-bin-first search
554554
Heap<BranchSt>* heap = new Heap<BranchSt>((int)size_);
@@ -557,6 +557,8 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
557557
int checks = 0;
558558
for (int i=0; i<trees_; ++i) {
559559
findNN(root[i], result, vec, checks, maxChecks, heap, checked);
560+
if ((checks >= maxChecks) && result.full())
561+
break;
560562
}
561563

562564
BranchSt branch;
@@ -748,8 +750,8 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
748750
Heap<BranchSt>* heap, std::vector<bool>& checked)
749751
{
750752
if (node->childs==NULL) {
751-
if (checks>=maxChecks) {
752-
if (result.full()) return;
753+
if ((checks>=maxChecks) && result.full()) {
754+
return;
753755
}
754756
for (int i=0; i<node->size; ++i) {
755757
int index = node->indices[i];

0 commit comments

Comments
 (0)