从Canny算子获得的边缘图像8UC1中,我想要遍历所有的白色像素并找到它们的8邻域。
作为第一步,我申请
findNonZero(edgesFromCanny, nonZeroCoordinates);只获取所有白色像素以增加计算时间。然后对nonZeroCoordinates中这些像素的坐标进行逐行排序,使得p(x=100,y =1)可以远离nonZeroCoordinates Mat中的p(x=100,y=2) (按列排列),而p(x=100,y =1)和p(x=101,y =1)在nonZeroCoordinates中是后续的(如果它们是边的话)。
如何(快速)检索p(x=100,y=1)的8邻域,同时考虑到它也是一种边缘?
发布于 2018-06-14 08:51:03
我找到了一个使用kNN的解决方案,但我不确定这个解决方案是否需要太多的计算,或者可以有一个更简单的解决方案:
vector<Point2f> edgesVec; //Insert all 2D points to this vector
flann::KDTreeIndexParams indexParams;
flann::Index kdtree(Mat(edgesVec).reshape(1), indexParams);
vector<float> query;
query.push_back(i); //Insert the 2D point we need to find neighbours to the query
query.push_back(j); //Insert the 2D point we need to find neighbours to the query
vector<int> indices;
vector<float> dists;
kdtree.radiusSearch(query, indices, dists, 1.5, 8);https://stackoverflow.com/questions/50851758
复制相似问题