我有一个组成蠕虫轮廓的有序点向量(用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));
}
}
}
这个函数的问题是当蜗杆弯曲很多时,即轮廓在一侧变得凹入,骨架切掉了角落,不再代表蜗杆的中心。我的解决方案是,如果它们是凹的,则移动段末端,纠正段和骨架。
关于一个非常省时的函数的任何建议,它将找到轮廓上的所有凹(或凸)点?
问题图片: