You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FLANN::knnSearch does not assert the kNN value #10548
FLANN returns garbage indices and distances when kNN is larger than its training dataset size.
More importantly, when kNN is slightly larger than the dataset size (e.g. kNN=3, size()=2), the returned indices beyond the dataset size are zeros, which creates silent, misleading correspondences.
Steps to reproduce
This is not a Python bug, it is also reproducible using C++
importnumpyasnpimportcv2kNN=7#Any number bigger that len(index_points) will doindex_points=np.array([[0, 1, 2], [3, 4, 5]], np.float32)
query_points=np.array([[1, 2, 3]], np.float32)
flann_index=cv2.flann.Indexifcv2.__version__.startswith('2') elsecv2.flann_Indexflann=flann_index(index_points, dict(algorithm=0, trees=5))
idx, dist=flann.knnSearch(query_points, kNN, params= {})
np.set_printoptions(formatter={'all':lambdax: '{0:.3g},'.format(x)})
print(idx)
print(dist)
Activity
[-]`FLANN::knnSearch` returns garbage[/-][+]`FLANN::knnSearch` does not assert the kNN value[/+]Merge master into fork (#1)
resolves opencv#10548 - `FLANN::knnSearch` garbage bug (when kNN is l…