| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 614 人关注过本帖
标题:求助。。。。。 帮忙解决一下 编译时 有问题
只看楼主 加入收藏
xiaoyufeifei
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-9-25
结帖率:66.67%
收藏
已结贴  问题点数:19 回复次数:5 
求助。。。。。 帮忙解决一下 编译时 有问题


#include
#include
#include
#include
#include


#define MB_SIZE        16
#define BLOCK_SIZE    8
#define PI (4.*atan(1.))
//---//
#define W 3

// image resolution
int  pels;   // number of pixel in a line (Y)
int  lines;  // number of lines in a picture (Y)
int  im_size; // number of pixel in a picture (Y)

int  cpels;   // number of pixel in a line (Cb or Cr)
int  clines;  // number of lines in a picture (Cb or Cr)
int  cim_size; // number of pixel in a picture (Cb or Cr)

int  p_blocks;//number of blocks in a line (Y)
int  l_blocks;//number of blocks (Y)

// initialize picture parameters
void Initialize (char inf1[100], char inf2[100] , char *argv[], int *p_quant);
void ReadImage (int frame_no , char inf[100], unsigned char *lum, unsigned char *cb, unsigned char *cr);
void WriteImage (int frame_no, char outf[100], unsigned char *re_lum, unsigned char *re_cb, unsigned char *re_cr);


double Weighting(double x);
double Constrst_dis(double x , double y , double z );
double Lum_dis(unsigned char *p_block , unsigned char *q_block ,double x ,double y);



double Average( unsigned char *p_block );
double Variance(unsigned char *p_block , double x);
double Covariance (unsigned char *p_block, unsigned char *q_block ,double x,double y );

//-----//
double Function1(double sum1 , double sum2,double sum3,double sum4,double sum5,double sum6);
double Function2(unsigned char *a[3] , unsigned char *b[3], int c[3]);




void main (int agrc, char *argv[])
{
    unsigned char *lum1, *cb1, *cr1;
    unsigned char *lum2, *cb2, *cr2;
    char inputfile1[100];
    char inputfile2[100];


   
    int i, j, r, s , k , p11[3], p22[3],p_quant ;
    double  ait , ct , pdmt , wt , pdmf,  pqm , sum1 , sum2 , sum3, sum4, sum5, sum6, ux1 ,uy1, k1;
    double  qx , qx1, qy , qxy ;
    unsigned char *p1[3], *p2[3], *p, *q;
   
    double M1, M2, M3, DDM, Dt;

    double f1 , f2 , Quality , ZMA , NZMA;




   Initialize (inputfile1, inputfile2, argv, &p_quant);
  

    // memory allocation, 2-D --> 1-D
    lum1 = (unsigned char *)malloc(im_size*sizeof(unsigned char));
    cb1 = (unsigned char *)malloc(cim_size*sizeof(unsigned char));
    cr1 = (unsigned char *)malloc(cim_size*sizeof(unsigned char));

    p1[0] = (unsigned char *)malloc(im_size*sizeof(unsigned char));
    p1[1] = (unsigned char *)malloc(im_size*sizeof(unsigned char));
    p1[2] = (unsigned char *)malloc(im_size*sizeof(unsigned char));
    p2[0] = (unsigned char *)malloc(im_size*sizeof(unsigned char));
    p2[1] = (unsigned char *)malloc(im_size*sizeof(unsigned char));
    p2[2] = (unsigned char *)malloc(im_size*sizeof(unsigned char));

        
    lum2 = (unsigned char *)malloc(im_size*sizeof(unsigned char));
    cb2 = (unsigned char *)malloc(cim_size*sizeof(unsigned char));
    cr2 = (unsigned char *)malloc(cim_size*sizeof(unsigned char));

    ait = 0.;
    ct = wt = pdmt = pdmf = pqm = sum1 = sum2 = sum3 = sum4 = sum5 = sum6 = ux1 =uy1 = ait;
    qx = qx1 = qy = qxy =0;
    M1 = M2 = M3 = DDM = Dt = 0.;
    k1 = 0.025*0.025;

    f1 = f2 = Quality = ZMA = NZMA = 0.;

    for(k=0; k<100; k++)
    {
        ReadImage (k , inputfile1, lum1, cb1, cr1);
        //---zhifangtu fucnction----//
        for(j = 0; j < pels; j ++)
            for(i = 0; i < lines; i ++)
            {
                if (lum1[i + j * pels] >= '0' && lum1[i + j * pels] <='85')
                {
                    *(p1[0]+ i + j * pels) = lum1[i + j * pels];
                    sum1 += lum1[i + j * pels];
                    p11[0]++;
                }
                else if (lum1[i + j * pels] >= '86' && lum1[i + j * pels] <='170')
                {
                    *(p1[1]+ i + j * pels) = lum1[i + j * pels];
                    sum2 += lum1[i + j * pels];
                    p11[1]++;
                }               
                else
                {
                    *(p1[2]+i + j * pels) = lum1[i + j * pels];
                    sum3 += lum1[i + j * pels];   
                    p11[2]++;
                }
            }
            sum1 = sum1/p11[0];
            sum2 = sum2/p11[1];
            sum3 = sum3/p11[2];

        ReadImage (k , inputfile2, lum2, cb2, cr2);
          for(j = 0; j < pels; j ++)
            for(i = 0; i < lines; i ++)
            {
                if (lum2[i + j * pels] >= '0' && lum2[i + j * pels] <='85')
                {
                    *(p2[0]+i + j * pels) = lum2[i + j * pels];
                    sum4 += lum2[i + j * pels];
                    p22[0]++;
                }

                else if (lum2[i + j * pels] >= '86' && lum2[i + j * pels] <='170')
                {
                    *(p2[1]+i + j * pels) = lum2[i + j * pels];
                    sum5 += lum2[i + j * pels];
                    p22[1]++;
                }
            
                else
                    {
                    *(p2[2]+i + j * pels) = lum2[i + j * pels];
                    sum6 += lum2[i + j * pels];
                    p22[2]++;
                    }

            }   
            sum4 = sum4/p22[0];
            sum5 = sum5/p22[1];
            sum6 = sum6/p22[2];
        //-----M1,M2-----//


        M1 = Function1(sum1, sum2, sum3, sum4, sum5 , sum6);
        
        M2 = Function2(p1, p2, p11);
        printf("M2 =  %f\n",M2);
   
        for(j = 0 ; j < 96; j++)
        {
            for(i =0 ; i< 96 ; i++)
            {
                lum2[i + j * pels] /= p_quant;
            }
        }

        for (r = 0; r < p_blocks ; r ++)
        {
            for (s = 0; s < l_blocks ; s ++)
            {
                p = &lum1[ r * 8 * pels + s * 8];
                q = &lum2[ r * 8 * pels + s * 8];
            
                ux1 =  Average( p );
                uy1 =  Average( q );    //the mean of the luminance on the block


                qx = Variance( p , ux1);
                qy = Variance( q, uy1);// the variance of the luminance on the block


                qxy = Covariance(p, q , ux1, uy1 );//the covariance of the lum on the block

                //-----//
               
                sum3 = qxy/(qx*qy + k1);

               
                sum4 += sum3;
                M3 = sum4/(p_blocks * l_blocks);



                 //-----//

                wt= Weighting ( ux1 );             // the weighting factor
                ait = Lum_dis( p, q, ux1 ,uy1);   // the lum distortion
                ct  = Constrst_dis( qx, qy, qxy ); // the constrst distortion
                pdmt = ct * ait ;                  // the block level perceptual distorion


                sum1 += wt * pdmt;
                sum2 += wt;

            }
        }

      

        pdmf = sum1/sum2;    // the frame level perceptual distorion
        pqm = 1 - pdmf;
                        
        if( pqm < 0 )
        {
            pqm = 0. ;

            printf("the result is: 0 .\n");
        }
            
        else

        printf("The result of the %3d-th frame is : %f \n ", k, pqm);

        
        DDM += M3/(M1*M2+1);
         
    }


    DDM = DDM/100;

    Dt = DDM*pqm;

    printf ("the Dt is %f\n", Dt);

    //------Combined Colour-Depth Quality Evaluation----//

    ux1 = qx = qx1 = 0.;

        for (r = 0; r < p_blocks ; r ++)
        {
            for (s = 0; s < l_blocks ; s ++)
            {
                for(k=0; k<100; k++)
                {
                    
                    p = &lum1[k*pels* lines + r * 8 * pels + s * 8];
                     ux1 =  Average( p );
                     qx1 += lum1[ k*pels*lines+ r * 8 * pels + s * 8]-ux1;

                }

                qx1 = sqrt(qx1/100 );

                ZMA += qx1;
            }
        }
    NZMA = ZMA/(pels*lines*255);

    f1 = 1 - 0.997*pow(NZMA , 0.2393);
    f2 = 0.997* pow(NZMA  , 0.2393);



   
    Quality = f1*pqm + f2*DDM;

    printf("The result of the Quality  is : %f \n ",  Quality);

   
    return;
}



void Initialize (char inf1[100], char inf2[100], char *argv[], int *p_quant)
{
    pels = 640;
    lines = 1024;

    cpels = pels/2;
    clines = lines/2;

    p_blocks = pels/BLOCK_SIZE;
    l_blocks = lines/BLOCK_SIZE;
   
    im_size = pels*lines;
    cim_size = cpels*clines;

    strcpy (inf1,argv[1]);
    strcpy (inf2,argv[2]);
    *p_quant = atoi(argv[3]);

   
    return ;
}

void ReadImage (int frame_no , char inf[100], unsigned char *lum, unsigned char *cb, unsigned char *cr)
{
    FILE *fin = NULL;

    fin = fopen(inf, "rb");
    if (fin == NULL)
    {
        fprintf(stderr,"\n%s file open failure !!!\n", inf);
        exit (0);
    }
    fseek(fin, sizeof(unsigned char) * im_size*3/2  * frame_no, 0);
    fread (lum, sizeof(unsigned char), im_size, fin);
    fread (cb,  sizeof(unsigned char), cim_size, fin);
    fread (cr,  sizeof(unsigned char), cim_size, fin);


    fclose (fin);
}



void WriteImage (int frame_no, char outf[100], unsigned char *lum,  unsigned char *cb,     unsigned char *cr)
{
    FILE *fout = NULL;

    if (frame_no == 0)
    {
        fout = fopen(outf, "wb");
    }
    else
    {
        fout = fopen(outf, "ab");
    }

    if (fout == NULL)
    {
        fprintf(stderr,"\n%s file open failure !!!\n", outf);
        exit (0);
    }
   
    fwrite (lum, sizeof(unsigned char), im_size, fout);
    fwrite (cb,  sizeof(unsigned char), cim_size, fout);
    fwrite (cr,  sizeof(unsigned char), cim_size, fout);

    fclose (fout);
}



double Average( unsigned char  *p_block )
{
    int i , j;
    double sum , ux;

    sum = ux = 0.;

    for(j = 0 ; j < BLOCK_SIZE; j++)
    {
        for(i =0 ; i< BLOCK_SIZE; i++)
        {
            sum += *(p_block+ i + j * pels);

        }
    }

    ux = sum/64.;

    return ux ;
}





double Variance(unsigned char *q_block , double x)

{
    int i , j;
    double  sum;

     sum = 0.;

     for(j = 0; j < BLOCK_SIZE; j ++)
     {
         for(i = 0; i < BLOCK_SIZE; i ++)
             {
                sum += ( *(q_block +i + j * pels)-x)*(*(q_block +i + j * pels)-x);
             }
         
     }
     sum = sqrt( sum / (BLOCK_SIZE*BLOCK_SIZE-1));

     return sum ;
   
}
//the variance of the block




double Covariance (unsigned char *p_block , unsigned char *q_block , double x , double y )
{

    int i , j;
    double sum;


    sum = 0.;

    for(j = 0; j < BLOCK_SIZE; j ++)
    {
        for(i = 0; i < BLOCK_SIZE; i ++)
        {
            sum += ( *(p_block +i + j * pels) - x ) * ( *(q_block +i + j * pels) - y );
        }

    }

    sum = sum / (BLOCK_SIZE*BLOCK_SIZE-1);

    return  sum;

}
//the covariance of the lum on the block



double Lum_dis(unsigned char *p_block , unsigned char *q_block, double x , double y)
{
    int i , j;
    double sum;

    sum=0.;
   
    if (x <= 1 && y <= 1)
        sum = 0.;
    else if (x<=1 && y > 1)
        sum = BLOCK_SIZE*BLOCK_SIZE;
    else
        for(j = 0 ; j < BLOCK_SIZE ; j ++)
            {
            for(i = 0; i < BLOCK_SIZE ; i ++)
                {
                sum = ( ( *(p_block +i + j * pels) -*(q_block +i + j * pels) ) * ( *(p_block +i + j * pels) -*(q_block +i + j * pels) ) ) / x;
                sum += pow( sum , 2);
                }
            }
        sum = sum/64.;

        return sum;
        
}//the lum distorition is calculated



double Weighting( double x )
{

    double sum;

    sum  = 0.;
   
    if( x == 0 )
        sum = 1.;
    else
        sum = 255/x ;

    return sum;
   
}//the weighting factor is calculated




double Constrst_dis(double x , double y , double z)
{
    double sum , sum0 ;

    sum = sum0 = 0.;


    sum0 = pow ( ( x * x - y * y ) , 2 ) + 255 ;
    sum = pow ( x , 4 ) + pow (y , 4 ) - 2 * pow ( z , 2 ) + 255;
    sum = 1 + sum0/sum;

    return sum;
   
   
}// the distortion in contrast

//-------DDM--------//
double Function1(double sum1 , double sum2,double sum3,double sum4,double sum5,double sum6)
{
    int kn, kf;
    double sum, ddr;

    kn = 255;
    kf = 0;
    sum = 0.;
    ddr = 0.;

    ddr = (kn*W + kf*W)/255*fabs((sum1-sum2)-(sum4-sum5));
    sum += ddr;
   
    ddr = (kn*W + kf*W)/255*fabs((sum2-sum3)-(sum5-sum6));
    sum += ddr;
   
    return sum;
         
}

double Function2(unsigned char *a[3], unsigned char *b[3], int c[3])
{
    double sum, sum1, sum2, sum3, u;
    double sum_diff[3][640*1024];
    int i , j;

    sum = sum1 = sum2 = sum3  = u = 0.;
    sum_diff[3][640*1024] = 0.;
   
    for(i = 0; i< 3; i ++)
    {

        for(j = 0; j< c[i]; j++)
        {
            sum_diff[i ][j]= a[i][j] - b[i][j];
            sum1 += sum_diff[i][j];
        }
        u = sum1/c[i];
        
        
        for(j = 0; j< c[i] ; j++)

            sum2 += sum_diff[i][ j] - u;

        sum2 = sum2/c[i];
        sum3 +=sqrt(sum2);
        
        sum += sum3;
    }
   
    return sum;

}

//-------//

搜索更多相关主题的帖子: 婴儿 include number image 
2011-10-24 17:17
xiaoyufeifei
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-9-25
收藏
得分:0 
在编译时 出现0x00e419f8 处未处理的异常: 0xC0000005: 写入位置 0x004e7000 时发生访问冲突
2011-10-24 17:19
skyn
Rank: 2
来 自:西南交通大学
等 级:论坛游民
帖 子:24
专家分:32
注 册:2011-10-17
收藏
得分:10 
把你include后面的修改一下- -,看不见.....

﹎'ひS.т.й.R.S.に`"
2011-10-24 17:25
xiaoyufeifei
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-9-25
收藏
得分:0 
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
2011-10-24 17:27
xiaoyufeifei
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2011-9-25
收藏
得分:0 
好像问题是出在二位数组指针的定义~~~~
2011-10-24 17:28
吴军旗
Rank: 5Rank: 5
等 级:职业侠客
帖 子:286
专家分:308
注 册:2011-9-14
收藏
得分:10 
别乱来,慢慢学吧。。。。

最惨的不是忘不了悲伤的回忆,而是那些悲伤的回忆却开始记不清。。。
2011-10-24 23:42
快速回复:求助。。。。。 帮忙解决一下 编译时 有问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.022095 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved