comparison scripts/display-trajectories.py @ 347:7b865f4174aa

updated script to display trajectories with argparse module
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 26 Jun 2013 17:28:45 -0400
parents dc2e68e936c7
children a50a69e04c2a
comparison
equal deleted inserted replaced
346:5f75d6c23ed5 347:7b865f4174aa
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 2
3 import sys,getopt 3 import sys, argparse
4 4
5 import storage, cvutils, utils 5 import storage, cvutils, utils
6 6
7 from numpy.linalg.linalg import inv 7 from numpy.linalg.linalg import inv
8 from numpy import loadtxt 8 from numpy import loadtxt
9 9
10 options, args = getopt.getopt(sys.argv[1:], 'hi:d:t:o:f:',['help']) 10 parser = argparse.ArgumentParser(description='The program displays feature or object trajectories overlaid over the video frames.', epilog = 'Either the configuration filename or the other parameters (at least video and database filenames) need to be provided.')
11 # alternative long names are a pain to support ,'video-filename=','database-filename=', 'type=' 11 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file')
12 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file')
13 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file')
14 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to display', choices = ['feature', 'object'], default = 'feature')
15 parser.add_argument('-o', dest = 'homography', help = 'name of the image to world homography')
16 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', default = 0, type = int)
12 17
13 # replace with argparse 18 args = parser.parse_args()
14 # type parser.add_argument('-t', choices=['feature', 'object'])
15 19
16 options = dict(options) 20 if args.configFilename: # consider there is a configuration file
17
18 print options, args
19
20 if '--help' in options.keys() or '-h' in options.keys() or len(sys.argv) == 1:
21 print('Usage: '+sys.argv[0]+' --help|-h -i video-filename -d database-filename [-t object_type] [-o image2world_homography] [-f first_frame]\n'
22 +'Or : '+sys.argv[0]+' [-t object_type] config_file.cfg\n\n'
23 'Order matters between positional and named arguments\n'
24 'object_type can be feature or object')
25 sys.exit()
26
27 objectType = 'feature'
28 if '-t' in options.keys():
29 objectType = options['-t']
30
31 if len(args)>0: # consider there is a configuration file
32 params = utils.TrackingParameters() 21 params = utils.TrackingParameters()
33 params.loadConfigFile(args[0]) 22 params.loadConfigFile(args.configFilename)
34 videoFilename = params.videoFilename 23 videoFilename = params.videoFilename
35 databaseFilename = params.databaseFilename 24 databaseFilename = params.databaseFilename
36 homography = inv(params.homography) 25 homography = inv(params.homography)
37 firstFrameNum = params.firstFrameNum 26 firstFrameNum = params.firstFrameNum
38 else: 27 else:
39 videoFilename = options['-i'] 28 videoFilename = args.videoFilename
40 databaseFilename = options['-d'] 29 databaseFilename = args.databaseFilename
41 homography = None 30 homography = None
42 if '-o' in options.keys(): 31 if args.homography:
43 homography = inv(loadtxt(options['-o'])) 32 homography = inv(loadtxt(args.homography))
44 firstFrameNum = 0 33 firstFrameNum = args.firstFrameNum
45 if '-f' in options.keys():
46 firstFrameNum = int(options['-f'])
47 34
48 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, objectType) 35 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType)
49 cvutils.displayTrajectories(videoFilename, objects, homography, firstFrameNum) 36 cvutils.displayTrajectories(videoFilename, objects, homography, firstFrameNum)