help='The column (0-based) containing the trajectory labels (default: -1, the last column)' ) parser.add_argument( '-t', '--show-trajectories', action='store_true', help='Show trajectories' ) args = parser.parse_args() file = args.file trajectory_column = args.trajectory_column show_trajectories = args.show_trajectories window = Window() f = open(file) desc = PointsDesc.from_string(f.read()) seq = desc.getSequence() window.setSequence(seq) if show_trajectories: if len(desc.frames) > 0: first_frame = desc.frames[0] if len(first_frame) > 0: nentries = len(first_frame[0]) # original number of columns = nentries+1 if trajectory_column < 0: trajectory_column += nentries+1 if trajectory_column < 3: raise Exception('Invalid trajectory column {0} (should be >= 3 since the three first entries are <f> <x> <y>)'.format(trajectory_column)) trajectory_column -= 1 trajs = desc.getTrajectories(trajectory_column)
return trajs #}}} if __name__ == "__main__": from pymage.vendor import argparse parser = argparse.ArgumentParser(description='ASTRE tracking algorithm (naive implementation)') parser.add_argument('filename_in', metavar='in', help='the input PointsDesc file') parser.add_argument('filename_out', metavar='out', help='the output PointsDesc file') parser.add_argument('-e', '--eps', dest='eps', default=0.0, type=float, help='the maximal value of log(NFA) when searching for meaningful trajectories (default: 0.0)') parser.add_argument('--solver', default='noholes', choices=['noholes', 'holes']) args = parser.parse_args() points = PointsDesc.from_string(open(args.filename_in).read()) if len(points.frames) < 3: raise ValueError('Input points file must have at least 3 images!') def load_frames(points): fs = [] for f in points.frames: fs.append(np.array([(p[0], p[1]) for p in f], dtype=np.float64)) return fs frames = load_frames(points) image_size = (points.width, points.height) eps = float(args.eps) if args.solver == 'noholes': solver = NoholesSolver(image_size, frames)