Search code examples
opencvdistancesampleknn

get distance from all samples in knn in opencv


as i know knn find smallest distance from all samples.it means it is the nearest sample. but what if i want distance of my new data from all samples? how can I get for example 3 or 4 nearest samples to my new data? Thank you


Solution

  • K nearest neighbour? That means that you can find K nearest samples. You should read documentation carefully. Example:

        kdtree.knnSearch(((cv::Mat)objects_coordinates[i_pts]).t(),
            indices, dists, num_of_neighbours, cv::flann::SearchParams(32));