zoukankan      html  css  js  c++  java
  • 【PE/Codecs】YUV文件比较的两种方法

    Date:2018.5.21


    1、方法一:将YUV读取到buffer中,然后每帧逐字节比较。C语言实现

    #include<stdio.h>
    #include <stdlib.h>
    #include <string>
    
    int main(int argc, char **argv)
    {
    	FILE *fin_1 = NULL;
    	FILE *fin_2 = NULL;
    	FILE *fout = NULL;
    
    	int srcwidth = 0, srcheight = 0;
    	int framesize = 0, in1_size = 0, in2_size = 0;
    	int srcframenum = 0;
    	unsigned char *buffer1 = NULL;
    	unsigned char *buffer2 = NULL;
    
    	if (argc!=5)
    	{
    		printf("Usage: CompareYUV.exe yuv0 yuv1 width height");
    		return -1;
    	}
    	fin_1 = fopen(argv[1],"rb");
    	if (!fin_1)
    	{
    		printf("Open input yuv0 failed!
    ");
    	}
    	fin_2 = fopen(argv[2], "rb");
    	if (!fin_2)
    	{
    		printf("Open input yuv1 failed!
    ");
    	}
    	fout = fopen("compare_result.txt", "a+");
    	if (!fout)
    	{
    		printf("Open compare_result.txt failed!
    ");
    	}
    
    	srcwidth = atoi(argv[3]);//width
    	srcheight = atoi(argv[4]);//height
    
    	framesize = srcheight*srcwidth * 3 / 2;//++YUV420采样格式
    
    
    	buffer1 = (unsigned char *)malloc(framesize*sizeof(unsigned char*));
    	buffer2 = (unsigned char *)malloc(framesize*sizeof(unsigned char*));
    	if ((buffer1 == NULL) ||(buffer2 == NULL))
    	{
    		printf("malloc buffer1 or buffer2 failed!
    ");
    	}
    
    	fprintf(fout, "%s VS %s!    ", argv[1], argv[2]);
    	while ((fread(buffer1, 1, framesize, fin_1) == framesize)&&(fread(buffer2, 1, framesize, fin_2) == framesize))
    	{
    		int i = 0;
    		for (i = 0; i < framesize; i++)
    		{
    			if (buffer1[i] != buffer2[i])
    			{
    				fprintf(fout, "framenum:%d  ", srcframenum);
    				fprintf(fout, "DISMATCH!
    ");
    				return -1;
    			}
    		}
    		srcframenum++;
    	}
    
    	fprintf(fout, "framenum:%d  ", srcframenum);
    	fprintf(fout, "MATCH!
    ");
    
    	
    	free(buffer1);
    	buffer1 = NULL;
    	free(buffer2);
    	buffer2 = NULL;
    
    	fclose(fin_1);
    	fclose(fin_2);
    	fclose(fout);
    
    	return 0;
    }

    方法二:Python中filecmp模块

        filecmp模块用于比较文件及文件夹的内容,它是一个轻量级的工具,使用非常简单。python标准库还提供了difflib模块用于比较文件的内容。

         filecmp定义了两个函数,用于方便地比较文件与文件夹:

    filecmp.cmp(f1, f2[, shallow])

    比较两个文件的内容是否匹配。参数f1, f2指定要比较的文件的路径。可选参数shallow指定比较文件时是否需要考虑文件本身的属性(通过os.stat函数可以获得文件属性)。如果文件内容匹配,函数返回True,否则返回False。

    说明:第一种C实现的方法比较基础,第二种Python函数的方法比较简洁。


    THE END!

  • 相关阅读:
    功能超级丰富的彩色贪吃蛇,有道具,有等级!
    【Android开发经验】LayoutInflater—— 你可能对它并不了解甚至错误使用
    数据库常见面试题总结
    数据结构——算法之(041)(寻找数组中的最大值和最小值)
    Riak VClock
    【面试虐菜】—— JAVA面试题(2)
    【面试虐菜】—— MongoDB知识整理
    【面试虐菜】—— Oracle知识整理《收获,不止Oracle》
    【面试虐菜】—— Oracle知识整理《DBA的思想天空》
    【面试虐菜】—— Oracle中CHAR、VARCHAR的区别
  • 原文地址:https://www.cnblogs.com/SoaringLee/p/10532473.html
Copyright © 2011-2022 走看看