我有一组openCV Point2f类型的图像点(坐标).我想找到该组中每个点的4个最近邻居.openCV中是否有任何特定的内置函数来执行此操作,还是应该测量每个点之间的距离并确定最接近的四个?
以下代码将有助于从一组点中找到所选点的最近邻居.
vector<Point2f> pointsForSearch; //Insert all 2D points to this vector
flann::KDTreeIndexParams indexParams;
flann::Index kdtree(Mat(pointsForSearch).reshape(1), indexParams);
vector<float> query;
query.push_back(pnt.x); //Insert the 2D point we need to find neighbours to the query
query.push_back(pnt.y); //Insert the 2D point we need to find neighbours to the query
vector<int> indices;
vector<float> dists;
kdtree.radiusSearch(query, indices, dists, range, numOfPoints);
Run Code Online (Sandbox Code Playgroud)
indices给出了所选邻居的索引,dists给出了所选邻居的距离.
| 归档时间: |
|
| 查看次数: |
13854 次 |
| 最近记录: |