Skip to content

Commit 5bc6b6f

Browse files
committed
Merge pull request opencv#17737 from pemmanuelviel:pev--fix-trees-descent
2 parents 8931c68 + 7286848 commit 5bc6b6f

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
@@ -547,7 +547,7 @@ class HierarchicalClusteringIndex : public NNIndex<Distance>
547547
void findNeighbors(ResultSet<DistanceType>& result, const ElementType* vec, const SearchParams& searchParams) CV_OVERRIDE
548548
{
549549

550-
int maxChecks = get_param(searchParams,"checks",32);
550+
const int maxChecks = get_param(searchParams,"checks",32);
551551

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

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

0 commit comments

Comments
 (0)