首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nonZeroCoordinates矢量中的8邻域

nonZeroCoordinates矢量中的8邻域
EN

Stack Overflow用户
提问于 2018-06-14 07:20:59
回答 1查看 31关注 0票数 0

从Canny算子获得的边缘图像8UC1中,我想要遍历所有的白色像素并找到它们的8邻域。

作为第一步,我申请

代码语言:javascript
复制
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邻域,同时考虑到它也是一种边缘?

EN

回答 1

Stack Overflow用户

发布于 2018-06-14 08:51:03

我找到了一个使用kNN的解决方案,但我不确定这个解决方案是否需要太多的计算,或者可以有一个更简单的解决方案:

代码语言:javascript
复制
    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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50851758

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档