void VessDibTrack(HDIB hdib,vector& pt) //八邻域
{
unsigned char *lpSrc;
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL)hdib);
int cxDIB = (int) ::DIBWidth(lpDIB); // Size of DIB - x
int cyDIB = (int) ::DIBHeight(lpDIB); // Size of DIB - y
LPSTR lpDIBBits=::FindDIBBits (lpDIB);
long lLineBytes = WIDTHBYTES(cxDIB * 8); // 计算图像每行的字节数
//寻找开始点,最右,最下
//先行,后列
int i,j;
POINT startPt,currPt;
for (i = 0;i
{
for (j = 0;j
{
lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB -1 - i) + j;
if (*lpSrc==0) //是黑点
{
startPt.x = i;
startPt.y = j;
//停止条件
i = cyDIB;
j = cxDIB;
}
}
}
//设置方向数组
// int direction[8][2] = {{-1,-1},{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0}};
int direction[8][2] = {{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1},{-1,-1},{-1,0}};
int startDirect ;
BOOL FindStartPoint = FALSE;
BOOL FindPoint = FALSE;
//开始跟踪
currPt.x = startPt.x;
currPt.y = startPt.y;
POINT NextPt ;
int NextPtValue;
startDirect = 0;
int cnt= 0;
while(!FindStartPoint&&cnt<100000)
{
FindPoint = FALSE;
pt.push_back(currPt);
while(!FindPoint)
{
//沿预定方向扫描,寻找下一个点
NextPt.x = currPt.x + direction[startDirect][1];
NextPt.y = currPt.y + direction[startDirect][0];
lpSrc = (unsigned char*)lpDIBBits + lLineBytes * (cyDIB -1 - NextPt.x) + NextPt.y;
//NextPtValue = GetPiexValue(hdib,NextPt.x,NextPt.y);
NextPtValue = * lpSrc;
if (NextPtValue == 0&&NextPt.x>=0&&NextPt.x=0&&NextPt.y
{
FindPoint = TRUE;
currPt.x = NextPt.x;
currPt.y = NextPt.y;
if (currPt.x == startPt.x&&currPt.y == startPt.y)
{
FindStartPoint = TRUE;
}
startDirect = startDirect-2;
if(startDirect<0) startDirect = startDirect+8;
}
else
{
startDirect = startDirect+1;
if (startDirect>=8) startDirect = startDirect-8;
}
}
cnt ++;
}
::GlobalUnlock((HGLOBAL) hdib);
}