区域标记

writen by  [email protected]


void   Cbiaoji1::biaoji(IplImage  * src)
{
    DWORD t1,t2,t0;
       x_sign
=0
     m_temp
=0;
     x_temp
=0;
     y_temp
=0;
        temp
=cvCreateImage(cvSize(src->width,src->height),8,1);
    
for(int j=0;j<temp->height;j++)
        
for(int i=0;i<temp->width;i++)
        
{
            CV_IMAGE_ELEM(temp,uchar,j,i)
=255;
        }

    
//    cvZero(temp);
    memset(flag,0,255);
int width=src->width;
int height=src->height;
        
//从左到右标号

  t1
=::GetTickCount();
        
for( j=1;j<height-1;j++)    // 每行
        {
            
for(int i=1;i<width-1;i++)    // 每列
            {
                
                
                
if(CV_IMAGE_ELEM(src,uchar,j,i)==0)//若当前点为黑点
                {    
                    
if(CV_IMAGE_ELEM(src,uchar,j-1,i+1)==0)//右上
                    {      
                        CV_IMAGE_ELEM(temp,uchar,j,i)
=CV_IMAGE_ELEM(temp,uchar,j-1,i+1);
                        x_temp
=CV_IMAGE_ELEM(temp,uchar,j-1,i+1);
                        flag[x_temp]
+=1;    
                        
if(CV_IMAGE_ELEM(src,uchar,j,i-1)==0&&CV_IMAGE_ELEM(temp,uchar,j,i-1)!=x_temp)//左前
                        {    
                            y_temp
=CV_IMAGE_ELEM(temp,uchar,j,i-1);
                            
for(int m=1;m<=height-1;m++)
                                
for(int n=1;n<=width-1;n++)
                                
{
                                    
if(CV_IMAGE_ELEM(temp,uchar,m,n)==y_temp)
                                    
{    
                                        flag[y_temp]
=0;
                                        CV_IMAGE_ELEM(temp,uchar,m,n)
=x_temp;
                                        flag[x_temp]
+=1;
                                    }

                                }

                        }
//end//左前
                        if(CV_IMAGE_ELEM(src,uchar,j-1,i-1)==0 &&CV_IMAGE_ELEM(temp,uchar,j-1,i-1)!=x_temp)//左上
                        {
                            y_temp
=CV_IMAGE_ELEM(temp,uchar,j-1,i-1);
                            
for(int m=1;m<=height-1;m++)
                                
for(int n=1;n<=width-1;n++)
                                
{
                                    
if(CV_IMAGE_ELEM(temp,uchar,m,n)==y_temp)
                                    
{    
                                        flag[y_temp]
=0;
                                    CV_IMAGE_ELEM(temp,uchar,m,n)
=x_temp;
                                        flag[x_temp]
+=1;
                                    }

                                }

                        }
//end//左上
                    }

                    
else if(CV_IMAGE_ELEM(src,uchar,j-1,i)==0)//正上
                    {
                    CV_IMAGE_ELEM(temp,uchar,j,i)
=CV_IMAGE_ELEM(temp,uchar,j-1,i);
                        x_temp
=CV_IMAGE_ELEM(temp,uchar,j-1,i);
                        flag[x_temp]
+=1;
                    }

                    
else if(CV_IMAGE_ELEM(src,uchar,j-1,i-1)==0)//左上
                    {
                        CV_IMAGE_ELEM(temp,uchar,j,i)
=CV_IMAGE_ELEM(temp,uchar,j-1,i-1);
                        x_temp
=CV_IMAGE_ELEM(temp,uchar,j-1,i-1);
                        flag[x_temp]
+=1;
                    }

                    
else if(CV_IMAGE_ELEM(src,uchar,j,i-1)==0)//左前
                    {
                        CV_IMAGE_ELEM(temp,uchar,j,i)
=CV_IMAGE_ELEM(temp,uchar,j,i-1);
                        x_temp
=CV_IMAGE_ELEM(temp,uchar,j,i-1);
                        flag[x_temp]
+=1;
                    }

                    
else//没有
                    {                
                        
++x_sign;
                        m_temp
=x_sign;
                        CV_IMAGE_ELEM(temp,uchar,j,i)
=m_temp;
                        flag[m_temp]
=1;
                    
//    cout<<x_sign<<endl;
                    }

                }
//end if
            }
// 每列
        t2=::GetTickCount();        
        }

        t0
=::GetTickCount();
            cout
<<"时间t2-t1为"<<t2-t1<<"t0-t2为"<<t0-t2<<"to-t1时为:"<<t0-t1<<endl;
        }
// end 每行

你可能感兴趣的:(区)