//寻找曲线 :
void findLines(Mat &binaryImg, vector> &outLines)
{
//八邻域
vector neighborPtVec;
neighborPtVec.push_back(Point(-1,-1));
neighborPtVec.push_back(Point(0,-1));
neighborPtVec.push_back(Point(1,-1));
neighborPtVec.push_back(Point(1,0));
neighborPtVec.push_back(Point(1,1));
neighborPtVec.push_back(Point(0,1));
neighborPtVec.push_back(Point(-1,1));
neighborPtVec.push_back(Point(-1,0));
Point firstPt;
while (findFirstPoint(binaryImg, firstPt))
{
deque line;//点的队列
line.push_back(firstPt);//存储第一个点
//由于第一个点不一定是线段的起始位置,
//因此两个方向都要查找
Point currPt = firstPt;//当前点
int currFlag = 0;//标志
Point nextPt;//下一个点
int nextFlag;//下一点的标志
while (findNextPoint(neighborPtVec, binaryImg, currPt, currFlag, nextPt, nextFlag))//一端
{
line.push_back(nextPt);//压入队列
currPt = nextPt;
currFlag = nextFlag;
}
//找另一端
currPt = firstPt;
currFlag = 0;
while (findNextPoint(neighborPtVec, binaryImg, currPt, currFlag, nextPt, nextFlag))
{
line.push_front(nextPt);
currPt = nextPt;
currFlag = nextFlag;//邻域与中心像素的位置
}
if (line.size() > 10)
{
outLines.push_back(line);
}
}
}