七个不变特征识别

writen by wqj1212@yahoo.com.cn

double   *  CRecognise::recogniseInvariantMoment(IplImage  * src)
{
        
float cx=0.0;
    
float cy=0.0;
    
float Mpq=0.0;
    
int width;
    
int height;
    
double q1=0.0,q2=0.0,q3=0.0,q4=0.0,q5=0.0,q6=0.0,q7=0.0;
    
double n20=0.0,n02=0.0,n11=0.0,n30=0.0,n12=0.0,n03=0.0,n21=0.0,n00=0.0;
    
double u20=0.0,u02=0.0,u11=0.0,u30=0.0,u12=0.0,u03=0.0,u21=0.0,u00=0.0;
    width
=src->width;
    height
=src->height;
  
for(int j=1;j<=height;j++)
      
for(int i=1;i<=width;i++)
      
{
          Mpq
+=(float)(CV_IMAGE_ELEM(src,uchar,j,i));
          cx
+=i*CV_IMAGE_ELEM(src,uchar,j,i);
          cy
+=j*CV_IMAGE_ELEM(src,uchar,j,i);
      }

      cx
/=Mpq;
      cy
/=Mpq;
    
    
for(j=1;j<=height;j++)
      
for(int i=1;i<=width;i++)
      
{
       u20
+=(i-cx)*(i-cx)*CV_IMAGE_ELEM(src,uchar,j,i);
       u02
+=(j-cy)*(j-cy)*CV_IMAGE_ELEM(src,uchar,j,i);
       u11
+=(i-cx)*(j-cy)*CV_IMAGE_ELEM(src,uchar,j,i);
       u30
+=(i-cx)*(i-cx)*(i-cx)*CV_IMAGE_ELEM(src,uchar,j,i);
       u12
+=(i-cx)*(j-cy)*(j-cy)*CV_IMAGE_ELEM(src,uchar,j,i);
       u03
+=(j-cy)*(j-cy)*(j-cy)*CV_IMAGE_ELEM(src,uchar,j,i);
       u21
+=(i-cx)*(i-cx)*(j-cy)*CV_IMAGE_ELEM(src,uchar,j,i);
       

   }

   u00
=Mpq;


  n20
=u20/(u00*u00);
  n02
=u02/(u00*u00);
  n11
=u11/(u00*u00);
  n30
=u30/sqrt(u00*u00*u00*u00*u00);
  n12
=u12/sqrt(u00*u00*u00*u00*u00);
  n03
=u03/sqrt(u00*u00*u00*u00*u00);
  n21
=u21/sqrt(u00*u00*u00*u00*u00);
  q1
=n20+n02;
  q2
=(n20-n02)*(n20-n02)+4*n11*n11;
  q3
=(n30-3*n12)*(n30-3*n12)+(n03+3*n21)*(n03+3*n21);
  q4
=(n30+n12)*(n30+n12)+(n03+n21)*(n03+n21);
  q5
=(n30-3*n12)*(n30-n12)*((n30+n12)*(n30+n12)-3*(n03+n21)*(n03+n21))+(3*n21-n03)*(n21+n03)*(3*(n30+n12)*(n30+n12)-(n03+n21)*(n03+n21));
  q6
=(n20-n02)*((n30+n12)*(n30+n12)-(n03+n21)*(n03+n21))+4*n11*(n30+n12)*(n03+n21);
  q7
=(3*n21-n03)*(n30+n12)*((n30+n12)*(n30+n12)-3*(n03+n21)*(n03+n21))+(3*n12-n30)*(n21+n03)*(3*(n30+n12)*(n30+n12)-(n03+n21)*(n03+n21));
double pt[7];
pt[
0]=q1;
*(pt+1)=q2;
*(pt+2)=q3;
*(pt+3)=q4;
*(pt+4)=q5;
*(pt+5)=q6;
*(pt+6)=q7;
return pt;


}

转载于:https://www.cnblogs.com/wqj1212/archive/2007/12/21/1009609.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值