【问题标题】:Finding indexes of convex points on a contour查找轮廓上凸点的索引
【发布时间】:2014-10-01 07:59:25
【问题描述】:

我有一个构成蠕虫轮廓的有序点向量(使用 opencv 找到)。我试图沿着蠕虫的骨架获得积分。我想非常快地做到这一点,所以有一个简单的分割功能:

void Worm::segmentWorm(void)
{
    int jump = 5;
    int numPoints = wormContour.size();

    int currentIndex = headIndex; //large circle in image w/overlay
    int endIndex = tailIndex;     //small circle in image w/overlay
    int matchingIndex;

    int direction = (endIndex - currentIndex)/abs(endIndex - currentIndex);

    int thisSideLength = abs(endIndex - currentIndex);
    int otherSideLength = numPoints - thisSideLength;

    double lengthPercentage;

    if (direction > 0) {
        while (currentIndex < endIndex - jump) {
            currentIndex += jump;

            lengthPercentage = (double)(endIndex - currentIndex)/(double)thisSideLength;
            matchingIndex = boundCheck((int)((lengthPercentage * otherSideLength) + endIndex), numPoints - 1);

            segments.push_back(pair<int, int>(currentIndex, matchingIndex));
        }
    } else if (direction < 0) {
        while (currentIndex > endIndex + jump) {
            currentIndex -= jump;

            lengthPercentage = (double)(currentIndex - endIndex)/(double)thisSideLength;
            matchingIndex = boundCheck((int)(-(lengthPercentage * otherSideLength) + endIndex), numPoints - 1);

            segments.push_back(pair<int, int>(currentIndex, matchingIndex));
        }
    }
}

这个函数的问题是当蠕虫弯曲很多时,即轮廓在一侧变得凹入骨架切角不再代表蠕虫的中心。我的解决方案是,如果线段是凹的,则将它们移动,纠正线段和骨架。

有什么建议可以找到轮廓上所有凹(或凸)点的高效函数吗?

问题图片:

【问题讨论】:

  • @Haris 我看过那个选项,但我的问题是让骨架上的点从头到尾排序。有什么想法吗?
  • 查找轮廓会按顺序为您提供点数。

标签: c++ opencv contour convex


【解决方案1】:

如果不进行一些几何计算,就无法从该数组中得到正确的点对。

一种解决方案是沿一侧迭代,然后使用法线找到点的对应物。我想如果蠕虫的宽度没有太大变化,您可以使用固定偏移长度来搜索另一点,并且对于另一点,使用另一侧点的子集,这意味着 BF 匹配应该非常快。然后您可以在迭代时更新偏移量和子集。

编辑:如果对方的索引的初始猜测不是很糟糕,那么暴力匹配甚至没有必要,因为你可以遍历边直到没有点更接近了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-08
    • 2012-02-25
    • 1970-01-01
    • 2021-07-31
    • 2012-11-06
    相关资源
    最近更新 更多