计算两个YUV视频序列的PSNR

/** 
* Calculate PSNR between 2 YUV420P file 
* @param url1     Location of first Input YUV file. 
* @param url2     Location of another Input YUV file. 
* @param w        Width of Input YUV file. 
* @param h        Height of Input YUV file. 
* @param num      Number of frames to process. 
*/  
#include<iostream>
using namespace std;
int simplest_yuv420_psnr(char *url1,char *url2,int w,int h,int num){  
    FILE *fp1=fopen(url1,"rb+");  
    FILE *fp2=fopen(url2,"rb+");  
    FILE *fp=fopen("Video_PSNR.txt","w");         //创建存取PSNR值信息的txt文件


    unsigned char *pic1=(unsigned char *)malloc(w*h);  
    unsigned char *pic2=(unsigned char *)malloc(w*h);  
    
    float Sum_PSNR=0;    //定义所有帧的PSNR和
    float average_PSNR;  //定义平均PSNR
    for(int i=0;i<num;i++){  
        fread(pic1,1,w*h,fp1);  
        fread(pic2,1,w*h,fp2);  
        double mse_sum=0,mse=0,psnr=0;  
        for(int j=0;j<w*h;j++){  
            mse_sum+=pow((double)(pic1[j]-pic2[j]),2);  
        }  
        mse=mse_sum/(w*h);  
        psnr=10*log10(255.0*255.0/mse);  
        printf("the %d frame PSNR is %5.3f\n",i,psnr);          
        fprintf(fp,"the %d frame PSNR is %5.3f\n",i,psnr);      //存取每一帧的PSNR值到txt
        Sum_PSNR+=psnr;
        fseek(fp1,w*h/2,SEEK_CUR);  
        fseek(fp2,w*h/2,SEEK_CUR);   

    }  
    average_PSNR=Sum_PSNR/num;
    printf("the average PSNR is %5.3f\n",average_PSNR);
    fprintf(fp,"the average PSNR is %5.3f\n",average_PSNR);     //存取所有帧的平均PSNR值到txt
    free(pic1);  
    free(pic2);  
    fclose(fp1);  
    fclose(fp2);  
    return 0;  
}  

int main()
{   
//参数分别为(原始视频序列,压缩后视频序列,宽,高,帧数);   
    simplest_yuv420_psnr("BasketballDrill_832x480_50.yuv","BQMall_832x480_60.yuv",832,480,5);  
//注意视频序列所在路径,默认的是跟当前工程在一个目录下,当然也可以自己指定
system("pause");
    }

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

rs勿忘初心

您的鼓励将是我的最大创动原动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值