38 The Kinect provides the color and depth images in an un-synchronized way. This means that the set of time stamps from the color images do not intersect with those of the depth images. Therefore, we need some way of associating color images to depth images. 40 For this purpose, you can use the ''associate.py'' script. It reads the time stamps from the rgb.txt file and the depth.txt file, and joins them by finding the best matches. 51 Reads a trajectory from a text file. 54 The file format is "stamp d1 d2 d3 ...", where stamp denotes the time stamp (to be matched) 55 and "d1 d2 d3.." is arbitary data (e.g., a 3D position and 3D orientation) associated to this timestamp. 61 dict -- dictionary of (stamp,data) tuples 66 lines = data.replace(
",",
" ").replace(
"\t",
" ").split(
"\n")
67 list = [[v.strip()
for v
in line.split(
" ")
if v.strip()!=
""]
for line
in lines
if len(line)>0
and line[0]!=
"#"]
68 list = [(float(l[0]),l[1:])
for l
in list
if len(l)>1]
71 def associate(first_list, second_list,offset,max_difference):
73 Associate two dictionaries of (stamp,data). As the time stamps never match exactly, we aim 74 to find the closest match for every input tuple. 77 first_list -- first dictionary of (stamp,data) tuples 78 second_list -- second dictionary of (stamp,data) tuples 79 offset -- time offset between both dictionaries (e.g., to model the delay between the sensors) 80 max_difference -- search radius for candidate generation 83 matches -- list of matched tuples ((stamp1,data1),(stamp2,data2)) 86 first_keys = first_list.keys()
87 second_keys = second_list.keys()
88 potential_matches = [(
abs(a - (b + offset)), a, b)
91 if abs(a - (b + offset)) < max_difference]
92 potential_matches.sort()
94 for diff, a, b
in potential_matches:
95 if a
in first_keys
and b
in second_keys:
98 matches.append((a, b))
103 if __name__ ==
'__main__':
106 parser = argparse.ArgumentParser(description=
''' 107 This script takes two data files with timestamps and associates them 109 parser.add_argument(
'first_file', help=
'first text file (format: timestamp data)')
110 parser.add_argument(
'second_file', help=
'second text file (format: timestamp data)')
111 parser.add_argument(
'--first_only', help=
'only output associated lines from first file', action=
'store_true')
112 parser.add_argument(
'--offset', help=
'time offset added to the timestamps of the second file (default: 0.0)',default=0.0)
113 parser.add_argument(
'--max_difference', help=
'maximally allowed time difference for matching entries (default: 0.02)',default=0.02)
114 args = parser.parse_args()
119 matches =
associate(first_list, second_list,float(args.offset),float(args.max_difference))
123 print(
"%f %s"%(a,
" ".join(first_list[a])))
126 print(
"%f %s %f %s"%(a,
" ".join(first_list[a]),b-float(args.offset),
" ".join(second_list[b])))
def read_file_list(filename)
def associate(first_list, second_list, offset, max_difference)
GLM_FUNC_DECL genType abs(genType const &x)