The KD tree stores the processed descriptors in such a way that it is actually faster to find the most similar descriptor when doing a match.
It is very easy to use kd-tree in OpenCV, I will give you an example for a flaneograph:
flann::GenericIndex< cvflann::L2<int> > *tree; // the flann searching tree tree = new flann::GenericIndex< cvflann::L2<int> >(descriptors, cvflann::KDTreeIndexParams(4)); // a 4 kd tree
Then, when you do the mapping:
const cvflann::SearchParams params(32); tree.knnSearch(queryDescriptors, indices, dists, 2, cvflann::SearchParams(8));
source share