多目标识别

writen by [email protected]

思路
1.先对图像标记。给每个目标一个标号。
2.然后计算每个被标号目标的NMI特征值,
3.然后这些NMI特征值与已知要识别目标NMI特征值比较。
如果差值小于某个阈值,就说明该目标就是要识别的目标。

BOOL Cbiaoji1::ObjectionExtrationNMI(IplImage  * src)
{
    DWORD t3,t4;
bool status=false;
    t3
=::GetTickCount();
    IplImage 
*imgOb=NULL;
    IplImage 
*obImageNMI[255];
    
float M[255];
    
float J[255];
    
float cx[255];
    
float cy[255];
    
for(int i=0;i<255;i++)
    
{
        M[i]
=0.0;
        J[i]
=0.0;
        cx[i]
=0.0;
        cy[i]
=0.0;
    obImageNMI[i]
=cvCreateImage(cvSize(src->width,src->height),8,1);
    cvZero(obImageNMI[i]);
    }

    imgOb
=cvCreateImage(cvSize(src->width,src->height),8,1);
cvZero(imgOb);
        
biaoji(src);
    
for(int t=0;t<=x_sign;t++)
    
{
        
if(flag[t]>0)
        
{
            
for(int m=0;m<src->height;m++)
            
for(int n=0;n<src->width;n++)
            
{
                
if(CV_IMAGE_ELEM(temp,uchar,m,n)==t)
                
{
                    CV_IMAGE_ELEM(obImageNMI[t],uchar,m,n)
=255;
                }

            }

            
for(int j=0;j<src->height;j++)
    
        
for(i=0;i<src->width;i++)
        
{

            
            M[t]
+=(int)CV_IMAGE_ELEM(obImageNMI[t],uchar,j,i );
            cx[t]
+=j*(int)CV_IMAGE_ELEM(obImageNMI[t],uchar,j,i);
            cy[t]
+=i*(int)CV_IMAGE_ELEM(obImageNMI[t],uchar,j,i);
    
            
        }

        
            
     cx[t]
/=M[t];
     cy[t]
/=M[t];

     
for(j=0;j<src->height;j++)
         
for( i=0;i<src->width;i++)
         
{
             J[t]
+=((j-cx[t])*(j-cx[t])+(i-cy[t])*(i-cy[t]))*(int)(CV_IMAGE_ELEM(obImageNMI[t],uchar,j,i));
             
         }

    J[t]
=sqrt(J[t])/M[t];
        }

    }

    
for(t=0;t<=x_sign;t++)
    
{
        
if(J[t]!=0)
        
{        cout<<"连通区"<<t<<"的NMI特征值"<<J[t]<<endl;
        
if((fabs(J[t]-ModelNMIFeature)/J[t])<=1-PiPei/100)
        
{
         
for(int m=0;m<src->height;m++)
            
for(int n=0;n<src->width;n++)
            
{
                
if(CV_IMAGE_ELEM(temp,uchar,m,n)==t)
                    CV_IMAGE_ELEM(imgOb,uchar,m,n)
=255;
          status
=true;
            }

        
        }
}

    
    }

    
for( i=0;i<255;i++)
    
{
    
cvReleaseImage(
&obImageNMI[i]);
    
    }

    cvCopy(imgOb,src);
        cvReleaseImage(
&imgOb);
            cvReleaseImage(
&temp);
            t4
=::GetTickCount();
            cout
<<"t4-t3="<<t4-t3<<endl;
            
if(status)
            
return true;
            
else
                
return false;
}

你可能感兴趣的:(目标)