gpt4 book ai didi

c++ - 寻找最近的邻居 - OpenCV

转载 作者:可可西里 更新时间:2023-11-01 18:19:06 31 4
gpt4 key购买 nike

我确实有一组 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);

indices 给出所选邻居的索引,dists 给出所选邻居的距离。

关于c++ - 寻找最近的邻居 - OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9825959/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com