请教用递归算法去图像离散点的函数堆栈溢出错误
xionw 2008-03-04 03:13:37 //p:指针数组 (ppbtarray=array [0..999] of pbytearray,存储BMP图像的像素扫描结果
//lplab:二维数组plab=array [0..1999,0..1999] of boolean
//width:bmp.width
//heigh:bmp.heigh
//x,y:当前坐标
//m_lianxushu:连续点计数
//lianxushu:离散点阀值
function DeleteScaterJudge(P:ppbtarray;lplab:plab;width,heigh,x,y,M_lianxushu,lianxushu:Integer):Boolean;
begin
if M_lianxushu>lianxushu then
begin
result:=True;
//lianxushu:=lianxushu+1;
Inc(lianxushu);
lplab[X,Y]:=True;
end;
Result:=False;
if M_lianxushu>lianxushu then
Result:=True
else if (x<width) and (y<heigh) then
//开始进入递归
begin
//下面
if (p[Y+1][x]=0)and not(lplab[Y+1,x]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x,y+1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=True;
end;
//左面
if (p[y][x-1]=0) and not(lplab[y,x-1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x-1,y,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//上面
if (p[y-1][x]=0) and not(lplab[y-1,x]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x,y-1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//右面
if (p[y][x+1]=0) and not(lplab[y,x+1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x+1,y,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//左上
if (p[y-1][x-1]=0) and not(lplab[y-1,x-1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x-1,y-1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//左下
if (p[y+1][x-1]=0) and not(lplab[y+1,x-1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x-1,y+1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//右上
if (p[y-1][x+1]=0) and not(lplab[y-1,x+1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x+1,y-1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
//右下
if (p[y+1][x+1]=0) and not(lplab[y+1,x+1]) and (y-1>0) and (x-1>0) then
begin
DeleteScaterJudge(p,lplab,width,heigh,x+1,y+1,M_lianxushu,lianxushu);
if M_lianxushu>lianxushu then
Result:=true
end;
end;
end;
调用函数时出现stack overflow的错误,请高手们指点一下
里面的错误请高手们指点一下,万分感谢