Advertisement
Guest User

Untitled

a guest
Jun 5th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.41 KB | None | 0 0
  1. from collections import defaultdict
  2. from operator import itemgetter
  3. from itertools import groupby
  4. from collections import deque
  5. import os
  6.  
  7.  
  8. class avs_auto:
  9.  
  10.     def load_and_compare(self, input_file1, input_file2, output_file1, output_file2, result_file):
  11.         self.load(input_file1, input_file2, output_file1, output_file2)
  12.         self.compare(output_file1, output_file2)
  13.         self.final(result_file)
  14.  
  15.     def load(self, fileIn1, fileIn2, fileOut1, fileOut2):
  16.         with open(fileIn1+'.txt') as fin1, open(fileIn2+'.txt') as fin2:
  17.             frame_rects = defaultdict(list)
  18.             for row in (map(str, line.split()) for line in fin1):
  19.                 id, frame, rect = row[0], row[2], [row[3],row[4],row[5],row[6]]
  20.                 frame_rects[frame].append(id)
  21.                 frame_rects[frame].append(rect)
  22.             frame_rects2 = defaultdict(list)
  23.             for row in (map(str, line.split()) for line in fin2):
  24.                 id, frame, rect = row[0], row[2], [row[3],row[4],row[5],row[6]]
  25.                 frame_rects2[frame].append(id)
  26.                 frame_rects2[frame].append(rect)
  27.  
  28.         with open(fileOut1+'.txt', 'w') as fout1, open(fileOut2+'.txt', 'w') as fout2:
  29.             for frame, rects in sorted(frame_rects.iteritems()):
  30.                 fout1.write('{{{}:{}}}\n'.format(frame, rects))
  31.             for frame, rects in sorted(frame_rects2.iteritems()):
  32.                 fout2.write('{{{}:{}}}\n'.format(frame, rects))
  33.                
  34.  
  35.     def compare(self, fileOut1, fileOut2):
  36.         with open(fileOut1+'.txt', 'r') as fin1:
  37.             with open(fileOut2+'.txt', 'r') as fin2:
  38.                 lines1 = fin1.readlines()
  39.                 lines2 = fin2.readlines()
  40.                 diff_lines = [l.strip() for l in lines1 if l not in lines2]
  41.                 diffs = defaultdict(list)
  42.                 with open(fileOut1+'x'+fileOut2+'.txt', 'w') as result_file:
  43.                     for line in diff_lines:
  44.                         d = eval(line)
  45.                         for k in d:
  46.                             list_ids = d[k]
  47.                             for i in range(0, len(d[k]), 2):
  48.                                 diffs[d[k][i]].append(k)
  49.                     for id_ in diffs:
  50.                         diffs[id_].sort()
  51.                         for k, g in groupby(enumerate(diffs[id_]), lambda (i, x): i - x):
  52.                             group = map(itemgetter(1), g)
  53.                             result_file.write('{0} {1} {2}\n'.format(id_, group[0], group[-1]))
  54.        
  55.  
  56.     def final(self, result_file):
  57.         with open(result_file+'.txt', 'r') as fin:
  58.             lines = (line.split() for line in fin)
  59.             for k, g in groupby(lines, itemgetter(0)):
  60.                 fst = next(g)
  61.                 lst = next(iter(deque(g, 1)), fst)
  62.                 with open('final/{}.avs'.format(k), 'w') as fout:
  63.                     fout.write('video0=ImageSource("ANTT\original\%06d.jpeg", {}, {}, 15)\n'.format(fst[1], lst[2]))
  64.                     fout.write('video1=ImageSource("ANTT2\original\%06d.jpeg", {}, {}, 15)\n'.format(fst[1], lst[2]))
  65.                     fout.write('video0=BilinearResize(video0,640,480)\n')
  66.                     fout.write('video1=BilinearResize(video1,640,480)\n')
  67.                     fout.write('StackHorizontal(video0,video1)')
  68.  
  69.  
  70.  
  71. #a = avs_auto()
  72. #a.load_and_compare('hw1','hw2','hw1x1','hw2x2','hw1x1xhw2x2')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement