int Move_detect::Regional_growth(IplImage* src,CvPoint start,int region_color,int change_color)//函数功能:对于二值图像src求连通阈
{
uchar* srcdata=(uchar*)src->imageData;
//8领域
int Region8_x[]={-1,0,1,1,1,0,-1,-1};
int Region8_y[]={-1,-1,-1,0,1,1,1,0};
//4邻域
//int Region8_x[]={0,1,0,-1};
//int Region8_y[]={-1,0,1,0};
long int temp1=0,temp2=0;
int x,y;
if (srcdata[start.y*src->widthStep+start.x]!=region_color)
{
return 0;
}
else
{
Region_x[temp2]=start.x;
Region_y[temp2]=start.y;
temp2++;
}
while(temp1<=(temp2-1)&&temp1<5600000&&temp2<=5600000)
{
//printf("temp1:%d\n",temp1);
//printf("temp2:%d\n",temp2);
for (int i=0;i<8;i++)
{
//Region_x和Region_y里存放连通域占集的坐标
x=Region8_x[i]+Region_x[temp1];
y=Region8_y[i]+Region_y[temp1];
if (x>=0&&x<src->width&&y>=0&&y<src->height)
{
if (srcdata[y*src->widthStep+x]==region_color)
{
srcdata[y*src->widthStep+x]=change_color;
Region_x[temp2]=x;
Region_y[temp2]=y;
temp2++;
}
}
}
temp1++;
}
return temp1;
}
{
uchar* srcdata=(uchar*)src->imageData;
//8领域
int Region8_x[]={-1,0,1,1,1,0,-1,-1};
int Region8_y[]={-1,-1,-1,0,1,1,1,0};
//4邻域
//int Region8_x[]={0,1,0,-1};
//int Region8_y[]={-1,0,1,0};
long int temp1=0,temp2=0;
int x,y;
if (srcdata[start.y*src->widthStep+start.x]!=region_color)
{
return 0;
}
else
{
Region_x[temp2]=start.x;
Region_y[temp2]=start.y;
temp2++;
}
while(temp1<=(temp2-1)&&temp1<5600000&&temp2<=5600000)
{
//printf("temp1:%d\n",temp1);
//printf("temp2:%d\n",temp2);
for (int i=0;i<8;i++)
{
//Region_x和Region_y里存放连通域占集的坐标
x=Region8_x[i]+Region_x[temp1];
y=Region8_y[i]+Region_y[temp1];
if (x>=0&&x<src->width&&y>=0&&y<src->height)
{
if (srcdata[y*src->widthStep+x]==region_color)
{
srcdata[y*src->widthStep+x]=change_color;
Region_x[temp2]=x;
Region_y[temp2]=y;
temp2++;
}
}
}
temp1++;
}
return temp1;
}