Go through all the file in destination path:
import os
import sys
def GetFileList(dir, fileList):
newDir = dir
if os.path.isfile(dir):
fileList.append(dir.decode('gbk'))
elif os.path.isdir(dir):
for s in os.listdir(dir):
newDir=os.path.join(dir,s)
GetFileList(newDir, fileList)
return fileList
def MyGetFileList(dir, filelist):
if os.path.isdir(dir):
for s in os.listdir(dir):
if re.match(r"([\s\S]*)\.yuv", s):
filelist.append(os.path.join(dir, s))
return filelist
ValueError: invalid literal for int() with base 10
When read file, we just want to calculate the ASCII value to achieve our goal. Here MAP is very important.
def CalculatePSNRForTwoYUVs(f1, f2, dir1, dir2):
d1 = dir1 + '\\' + f1
d2 = dir2 + '\\' + f2
if (os.path.isfile(d1) and os.path.isfile(d2)):
file1Object = open(d1, 'r')
file2Object = open(d2, 'r')
while True:
chunk1 = file1Object.read(1)
chunk2 = file2Object.read(1)
if chunk1 == '':
break
#print string.atoi(chunk1)
ck1 = map(ord, chunk1)
print ck1[0]
def CalculatePSNRForTwoYUVs(f1, f2, dir1, dir2):
d1 = dir1 + '\\' + f1
d2 = dir2 + '\\' + f2
sumOfPSNR = 0
if (os.path.isfile(d1) and os.path.isfile(d2)):
file1Object = open(d1, 'r')
file2Object = open(d2, 'r')
print d1
print d2
while True:
chunk1 = file1Object.read(1)
chunk2 = file2Object.read(1)
if chunk1 == '':
break
if chunk2 == '':
break
ck1 = map(ord, chunk1)