convert.py
Go to the documentation of this file.
00001 from opencv import *
00002 import numpy
00003 import scipy
00004 import sys
00005 import os
00006 from string import split, strip
00007 import itertools
00008 from array import array
00009 from scipy.io.numpyio import fwrite, fread
00010 
00011 
00012 
00013 
00014 def group(lst, n):
00015     """group([0,3,4,10,2,3], 2) => iterator
00016 
00017     Group an iterable into an n-tuples iterable. Incomplete tuples
00018     are discarded e.g.
00019 
00020     >>> list(group(range(10), 3))
00021     [(0, 1, 2), (3, 4, 5), (6, 7, 8)]
00022     """
00023     return itertools.izip(*[itertools.islice(lst, i, None, n) for i in range(n)])
00024 
00025 
00026 def read_bb(bb_name):
00027     bb_dict = {}
00028     bb_file = open(bb_name,"r")
00029     for line in bb_file:
00030         items = split(line)
00031         bb_dict[items[0]] = map(int,items[1:])
00032     bb_file.close()
00033     return bb_dict
00034 
00035 
00036 def convert(bb_name, output_file):
00037     bb_dict = read_bb(bb_name)
00038     bb_cv_dict = {}
00039     file = open(output_file,"w")
00040     for key, bb_list in bb_dict.items():
00041         count = 0
00042         for i in range(0,len(bb_list),4):
00043             bb_list[i+2] -= bb_list[i]
00044             bb_list[i+3] -= bb_list[i+1]
00045             count +=1
00046         print >>file, key, count,
00047         for bb in bb_list:
00048             print >>file, bb,
00049         print >>file
00050     
00051 if __name__=="__main__":
00052     if len(sys.argv)<2:
00053         print "Usage: %s input_file output_file"%sys.argv[0]
00054         sys.exit(1)
00055 
00056     convert(sys.argv[1], sys.argv[2])
00057     


door_handle_detector
Author(s): Radu Bogdan Rusu, Marius
autogenerated on Wed Dec 11 2013 14:17:00