# flann : knn-search for hierarchical kmeans tree giving weird result

I have about 130,000 SIFT descriptors. I am building a hierarchical Kmeans-index using Opencv's flann module. After this I want to quantize these 130,000 descriptors (will quantize more later). I am using flann's knnsearch method for doing this. But the result of this method is something weird. For every descriptor the nearest index it is showing is the index of the descriptor itself. However, it should be displaying the cluster-ID of the nearest cluster which will be one of the leaves of the HIK-tree.

Should I try k=2

Here is a code snippet -

int k=1;
cv::flann::KMeansIndexParams indexParams(8,4,cvflann::FLANN_CENTERS_KMEANSPP) ;
cv::flann::Index hik_tree(cluster_data, indexParams);
Mat indices,dist;
hik_tree.knnSearch(cluster_data, indices, dist, k, cv::flann::SearchParams(64));

edit retag close merge delete

Sort by » oldest newest most voted

Yes, use k=2 (and then first look at the first match, if it is the same index then take the second closest match), since you build your index with the same cluster_data as you are doing your knnSearch, i.e. you match the same data with each other. Thus, the first result will with very high probability be the same index since it is typically the closest one.

Btw.: I'd raise or at least try out other branching factors and number of iterations for your KMenasIndexParams, 8 and 4 seem pretty low.

more

Official site

GitHub

Wiki

Documentation