【发布时间】: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 我看过那个选项,但我的问题是让骨架上的点从头到尾排序。有什么想法吗?
-
查找轮廓会按顺序为您提供点数。