2012年3月13日

影像處理:八連通遞迴

void __fastcall TForm1::Eight_Adjacency(IplImage *frame,int w,int h,int* Top_Width,int* Top_Height,int* Down_Width,int* Down_Height)
{
temp=cvScalar(0,0,0);
cvSet2D(frame,h,w,temp);
if(w!=frame->width-2)
{
temp=cvGet2D(frame,h,w+1);
if(temp.val[0]==255)
{

Eight_Adjacency(frame,w+1,h,Top_Width,Top_Height,Down_Width,Down_Height);
}
}

if((w!=frame->width-2)&&(h!=frame->height-2))
{
temp=cvGet2D(frame,h+1,w+1);
if(temp.val[0]==255)
{

Eight_Adjacency(frame,w+1,h+1,Top_Width,Top_Height,Down_Width,Down_Height);
}
}
if(h!=frame->height-2)
{
temp=cvGet2D(frame,h+1,w);
if(temp.val[0]==255)
{


Eight_Adjacency(frame,w,h+1,Top_Width,Top_Height,Down_Width,Down_Height);
}
}
if((h!=frame->height-2)&&(w!=2))
{
temp=cvGet2D(frame,h+1,w-1);
if(temp.val[0]==255)
{

Eight_Adjacency(frame,w-1,h+1,Top_Width,Top_Height,Down_Width,Down_Height);
}
}
if(w!=2)
{
temp=cvGet2D(frame,h,w-1);
if(temp.val[0]==255)
{

Eight_Adjacency(frame,w-1,h,Top_Width,Top_Height,Down_Width,Down_Height);
}
}
if((h!=2)&&(w!=2))
{
temp=cvGet2D(frame,h-1,w-1);
if(temp.val[0]==255)
{

Eight_Adjacency(frame,w-1,h-1,Top_Width,Top_Height,Down_Width,Down_Height);
}
}
if(h!=2)
{
temp=cvGet2D(frame,h-1,w);
if(temp.val[0]==255)
{


Eight_Adjacency(frame,w,h-1,Top_Width,Top_Height,Down_Width,Down_Height);
}
}
if((h!=2)&&(w!=frame->width-2))
{
temp=cvGet2D(frame,h-1,w+1);
if(temp.val[0]==255)
{

Eight_Adjacency(frame,w+1,h-1,Top_Width,Top_Height,Down_Width,Down_Height);
}
}

}

1 則留言:

  1. 遞迴是拿硬體資源換取程式結構複雜度,在嵌入式裡不要輕易嘗試...

    回覆刪除