Mercurial Hosting > traffic-intelligence
comparison python/display-trajectories.py @ 304:20f9cd972dde
added capability to parse cfg file for display-trajectories.py
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 29 Mar 2013 16:56:23 -0400 |
parents | 93c26e45efd8 |
children | c9201f6b143a |
comparison
equal
deleted
inserted
replaced
303:514f6b98cd8c | 304:20f9cd972dde |
---|---|
2 | 2 |
3 import sys,getopt | 3 import sys,getopt |
4 | 4 |
5 import storage | 5 import storage |
6 import cvutils | 6 import cvutils |
7 from utils import FakeSecHead | |
7 | 8 |
8 from numpy.linalg.linalg import inv | 9 from numpy.linalg.linalg import inv |
9 from numpy import loadtxt | 10 from numpy import loadtxt |
11 from ConfigParser import ConfigParser | |
10 | 12 |
11 options, args = getopt.getopt(sys.argv[1:], 'hi:d:t:o:f:',['help']) | 13 options, args = getopt.getopt(sys.argv[1:], 'hi:d:t:o:f:',['help']) |
12 # alternative long names are a pain to support ,'video-filename=','database-filename=', 'type=' | 14 # alternative long names are a pain to support ,'video-filename=','database-filename=', 'type=' |
13 # todo parse the cfg file (problem, python ConfigParser needs section headers) | 15 |
14 options = dict(options) | 16 options = dict(options) |
15 | 17 |
16 if '--help' in options.keys() or '-h' in options.keys() or len(sys.argv) == 1 or not '-i' in options.keys() or not '-d' in options.keys(): | 18 print options, args |
17 print('Usage: {0} --help|-h -i video-filename -d database-filename [-t object_type] [-o image2world_homography] [-f first_frame]'.format(sys.argv[0])) | 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') | |
18 sys.exit() | 25 sys.exit() |
19 | 26 |
20 objectType = 'feature' | 27 objectType = 'feature' |
21 if '-t' in options.keys(): | 28 if '-t' in options.keys(): |
22 objectType = options['-t'] | 29 objectType = options['-t'] |
23 | 30 |
24 objects = storage.loadTrajectoriesFromSqlite(options['-d'], objectType) | 31 if len(args)>0: # consider there is a configuration file |
32 config = ConfigParser() | |
33 config.readfp(FakeSecHead(open(args[0]))) | |
34 sectionHeader = config.sections()[0] | |
35 videoFilename = config.get(sectionHeader, 'video-filename') | |
36 databaseFilename = config.get(sectionHeader, 'database-filename') | |
37 homography = inv(loadtxt(config.get(sectionHeader, 'homography-filename'))) | |
38 firstFrameNum = config.getint(sectionHeader, 'frame1') | |
39 else: | |
40 videoFilename = options['-i'] | |
41 databaseFilename = options['-d'] | |
42 homography = None | |
43 if '-o' in options.keys(): | |
44 homography = inv(loadtxt(options['-o'])) | |
45 firstFrameNum = 0 | |
46 if '-f' in options.keys(): | |
47 firstFrameNum = int(options['-f']) | |
25 | 48 |
26 homography = None | 49 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, objectType) |
27 if '-o' in options.keys(): | 50 cvutils.displayTrajectories(videoFilename, objects, homography, firstFrameNum) |
28 homography = inv(loadtxt(options['-o'])) | |
29 firstFrameNum = 0 | |
30 if '-f' in options.keys(): | |
31 firstFrameNum = int(options['-f']) | |
32 | |
33 cvutils.displayTrajectories(options['-i'], objects, homography, firstFrameNum) |