Mercurial Hosting > traffic-intelligence
annotate python/display-trajectories.py @ 323:efd4dd4665ac
corrected issues with large deltas
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 08 May 2013 00:19:28 +0200 |
parents | 20f9cd972dde |
children | c9201f6b143a |
rev | line source |
---|---|
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
3 import sys,getopt |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
4 |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
5 import storage |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
6 import cvutils |
304
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
7 from utils import FakeSecHead |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
8 |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
9 from numpy.linalg.linalg import inv |
239
93c26e45efd8
modified functions to read velocities from sqlite database
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
236
diff
changeset
|
10 from numpy import loadtxt |
304
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
11 from ConfigParser import ConfigParser |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
13 options, args = getopt.getopt(sys.argv[1:], 'hi:d:t:o:f:',['help']) |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
14 # alternative long names are a pain to support ,'video-filename=','database-filename=', 'type=' |
304
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
15 |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
16 options = dict(options) |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
17 |
304
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
18 print options, args |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
19 |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
20 if '--help' in options.keys() or '-h' in options.keys() or len(sys.argv) == 1: |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
21 print('Usage: '+sys.argv[0]+' --help|-h -i video-filename -d database-filename [-t object_type] [-o image2world_homography] [-f first_frame]\n' |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
22 +'Or : '+sys.argv[0]+' [-t object_type] config_file.cfg\n\n' |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
23 'Order matters between positional and named arguments\n' |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
24 'object_type can be feature or object') |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
25 sys.exit() |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
26 |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
27 objectType = 'feature' |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
28 if '-t' in options.keys(): |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
29 objectType = options['-t'] |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
30 |
304
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
31 if len(args)>0: # consider there is a configuration file |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
32 config = ConfigParser() |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
33 config.readfp(FakeSecHead(open(args[0]))) |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
34 sectionHeader = config.sections()[0] |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
35 videoFilename = config.get(sectionHeader, 'video-filename') |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
36 databaseFilename = config.get(sectionHeader, 'database-filename') |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
37 homography = inv(loadtxt(config.get(sectionHeader, 'homography-filename'))) |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
38 firstFrameNum = config.getint(sectionHeader, 'frame1') |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
39 else: |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
40 videoFilename = options['-i'] |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
41 databaseFilename = options['-d'] |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
42 homography = None |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
43 if '-o' in options.keys(): |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
44 homography = inv(loadtxt(options['-o'])) |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
45 firstFrameNum = 0 |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
46 if '-f' in options.keys(): |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
47 firstFrameNum = int(options['-f']) |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
48 |
304
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
49 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, objectType) |
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
50 cvutils.displayTrajectories(videoFilename, objects, homography, firstFrameNum) |