区域标记

writen by  wqj1212@yahoo.com.cn


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 每行
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值