Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from collections import defaultdict
- from operator import itemgetter
- from itertools import groupby
- from collections import deque
- import os
- class avs_auto:
- def load_and_compare(self, input_file1, input_file2, output_file1, output_file2, result_file):
- self.load(input_file1, input_file2, output_file1, output_file2)
- self.compare(output_file1, output_file2)
- self.final(result_file)
- def load(self, fileIn1, fileIn2, fileOut1, fileOut2):
- with open(fileIn1+'.txt') as fin1, open(fileIn2+'.txt') as fin2:
- frame_rects = defaultdict(list)
- for row in (map(str, line.split()) for line in fin1):
- id, frame, rect = row[0], row[2], [row[3],row[4],row[5],row[6]]
- frame_rects[frame].append(id)
- frame_rects[frame].append(rect)
- frame_rects2 = defaultdict(list)
- for row in (map(str, line.split()) for line in fin2):
- id, frame, rect = row[0], row[2], [row[3],row[4],row[5],row[6]]
- frame_rects2[frame].append(id)
- frame_rects2[frame].append(rect)
- with open(fileOut1+'.txt', 'w') as fout1, open(fileOut2+'.txt', 'w') as fout2:
- for frame, rects in sorted(frame_rects.iteritems()):
- fout1.write('{{{}:{}}}\n'.format(frame, rects))
- for frame, rects in sorted(frame_rects2.iteritems()):
- fout2.write('{{{}:{}}}\n'.format(frame, rects))
- def compare(self, fileOut1, fileOut2):
- with open(fileOut1+'.txt', 'r') as fin1:
- with open(fileOut2+'.txt', 'r') as fin2:
- lines1 = fin1.readlines()
- lines2 = fin2.readlines()
- diff_lines = [l.strip() for l in lines1 if l not in lines2]
- diffs = defaultdict(list)
- with open(fileOut1+'x'+fileOut2+'.txt', 'w') as result_file:
- for line in diff_lines:
- d = eval(line)
- for k in d:
- list_ids = d[k]
- for i in range(0, len(d[k]), 2):
- diffs[d[k][i]].append(k)
- for id_ in diffs:
- diffs[id_].sort()
- for k, g in groupby(enumerate(diffs[id_]), lambda (i, x): i - x):
- group = map(itemgetter(1), g)
- result_file.write('{0} {1} {2}\n'.format(id_, group[0], group[-1]))
- def final(self, result_file):
- with open(result_file+'.txt', 'r') as fin:
- lines = (line.split() for line in fin)
- for k, g in groupby(lines, itemgetter(0)):
- fst = next(g)
- lst = next(iter(deque(g, 1)), fst)
- with open('final/{}.avs'.format(k), 'w') as fout:
- fout.write('video0=ImageSource("ANTT\original\%06d.jpeg", {}, {}, 15)\n'.format(fst[1], lst[2]))
- fout.write('video1=ImageSource("ANTT2\original\%06d.jpeg", {}, {}, 15)\n'.format(fst[1], lst[2]))
- fout.write('video0=BilinearResize(video0,640,480)\n')
- fout.write('video1=BilinearResize(video1,640,480)\n')
- fout.write('StackHorizontal(video0,video1)')
- #a = avs_auto()
- #a.load_and_compare('hw1','hw2','hw1x1','hw2x2','hw1x1xhw2x2')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement