FLANN in opencv runs too slow

Viewed 2951

I have a set of point cloub(number of point cloub≈2million). I would like to find the nearest k neighbor for each point within the point cloub. I did something like this

flann::Index flann_index(data_m, flann::KDTreeIndexParams(),cvflann::FLANN_DIST_EUCLIDEAN);// create the object of flann
    for (int i = 0; i < numberOfPointsInPointCloub; i++){
    flann_index.knnSearch(data_m.row(i), indices, dists,num_of_knn); //each row is a new set of point in 3D
    ..//save the results "dist" and "indices" in somewhere else
}

But this runs very slow. Within the for loop, it runs 1000 times for 20 seconds which is very slow. Am I use it wrongly? Or are there any method so that I can speed it up?

Update: The query point that I need to search is exactly the point used to construct the tree, I need to find the nearest k neighbor for each of the point within the tree thus I take the point from each row of the data and perform a knnSearch.

1 Answers
Related