我有两组点(cv::Point2f):setA和setB。对于setA中的每个点,我想在setB中找到其最近的邻居。因此,我尝试了两种方法:
Linear search: for each point in setA, just simply scan through all points in setB to find nearest one.
Using opencv kd-tree:
_ First I built a kd-tree for setB using opencv flann:
cv::flann::KDTreeIndexParams indexParams; cv::flann::Index kdTree(cv::Mat(setB).reshape(1), indexParams);
_ Then, for each point in setA I do query to find nearest neighbor:
kdTree.knnSearch(point_in_setA, indices, dists, maxPoints);