Mercurial Hosting > traffic-intelligence
annotate scripts/display-trajectories.py @ 684:6d2ece4aed7c dev
bug forgot to svae objects
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 05 Jun 2015 13:26:51 +0200 |
parents | 3058e00887bc |
children | 95e7622b11be |
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 |
347
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
3 import sys, argparse |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
4 |
333
c9201f6b143a
moved the config parser to utils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
304
diff
changeset
|
5 import storage, cvutils, utils |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
6 |
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
7 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
|
8 from numpy import loadtxt |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
9 |
347
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
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.') |
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
11 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') |
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
12 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file') |
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
13 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file') |
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
14 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to display', choices = ['feature', 'object'], default = 'feature') |
492 | 15 parser.add_argument('-o', dest = 'homographyFilename', help = 'name of the image to world homography file') |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
16 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
17 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
18 parser.add_argument('--undistorted-multiplication', dest = 'undistortedImageMultiplication', help = 'undistorted image multiplication', type = float) |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
19 parser.add_argument('-u', dest = 'undistort', help = 'undistort the video (because features have been extracted that way)', action = 'store_true') |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
20 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int) |
385
1917db662aa7
added rescaling options to scripts play-video and display-trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
364
diff
changeset
|
21 parser.add_argument('-r', dest = 'rescale', help = 'rescaling factor for the displayed image', default = 1., type = float) |
478
d337bffd7283
Display of points in compute homography and step option to replay videos
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
393
diff
changeset
|
22 parser.add_argument('-s', dest = 'nFramesStep', help = 'number of frames between each display', default = 1, type = int) |
482
f6415f012640
adding functionalities (save images directly to display trajectories to create movies
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
478
diff
changeset
|
23 parser.add_argument('--save-images', dest = 'saveAllImages', help = 'save all images', action = 'store_true') |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
24 parser.add_argument('--last-frame', dest = 'lastFrameNum', help = 'number of last frame number to save (for image saving, no display is made)', type = int) |
304
20f9cd972dde
added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
239
diff
changeset
|
25 |
347
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
26 args = parser.parse_args() |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
27 |
347
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
28 if args.configFilename: # consider there is a configuration file |
536
95276d310972
renamed TrackingParameters to ProcessParameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
528
diff
changeset
|
29 params = storage.ProcessParameters(args.configFilename) |
333
c9201f6b143a
moved the config parser to utils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
304
diff
changeset
|
30 videoFilename = params.videoFilename |
c9201f6b143a
moved the config parser to utils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
304
diff
changeset
|
31 databaseFilename = params.databaseFilename |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
32 if params.homography is not None: |
528
5585ebd8ad61
corrected bugs for trajectory display for new code versions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
514
diff
changeset
|
33 homography = inv(params.homography) |
5585ebd8ad61
corrected bugs for trajectory display for new code versions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
514
diff
changeset
|
34 else: |
5585ebd8ad61
corrected bugs for trajectory display for new code versions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
514
diff
changeset
|
35 homography = None |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
36 intrinsicCameraMatrix = params.intrinsicCameraMatrix |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
37 distortionCoefficients = params.distortionCoefficients |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
38 undistortedImageMultiplication = params.undistortedImageMultiplication |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
39 undistort = params.undistort |
333
c9201f6b143a
moved the config parser to utils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
304
diff
changeset
|
40 firstFrameNum = params.firstFrameNum |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
41 else: |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
42 homography = None |
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
43 undistort = False |
512
81ff62a7c39f
corrected bug so it can work without undistortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
509
diff
changeset
|
44 intrinsicCameraMatrix = None |
81ff62a7c39f
corrected bug so it can work without undistortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
509
diff
changeset
|
45 distortionCoefficients = [] |
81ff62a7c39f
corrected bug so it can work without undistortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
509
diff
changeset
|
46 undistortedImageMultiplication = None |
81ff62a7c39f
corrected bug so it can work without undistortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
509
diff
changeset
|
47 firstFrameNum = 0 |
364
a50a69e04c2a
script modification so that command line arguments take precedence over config file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
347
diff
changeset
|
48 |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
49 if not args.configFilename and args.videoFilename is not None: |
347
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
50 videoFilename = args.videoFilename |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
51 if not args.configFilename and args.databaseFilename is not None: |
347
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
52 databaseFilename = args.databaseFilename |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
53 if not args.configFilename and args.homographyFilename is not None: |
492 | 54 homography = inv(loadtxt(args.homographyFilename)) |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
55 if not args.configFilename and args.intrinsicCameraMatrixFilename is not None: |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
56 intrinsicCameraMatrix = loadtxt(args.intrinsicCameraMatrixFilename) |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
57 if not args.configFilename and args.distortionCoefficients is not None: |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
58 distortionCoefficients = args.distortionCoefficients |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
59 if not args.configFilename and args.undistortedImageMultiplication is not None: |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
60 undistortedImageMultiplication = args.undistortedImageMultiplication |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
586
diff
changeset
|
61 if args.firstFrameNum is not None: |
347
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
62 firstFrameNum = args.firstFrameNum |
236
eb4525853030
added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
63 |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
64 |
347
7b865f4174aa
updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
337
diff
changeset
|
65 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType) |
586
ff4f0ce46ca6
modified name for loading bounding boxes (only for display)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
536
diff
changeset
|
66 boundingBoxes = storage.loadBoundingBoxTableForDisplay(databaseFilename) |
509
935430b1d408
corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
492
diff
changeset
|
67 cvutils.displayTrajectories(videoFilename, objects, boundingBoxes, homography, firstFrameNum, args.lastFrameNum, rescale = args.rescale, nFramesStep = args.nFramesStep, saveAllImages = args.saveAllImages, undistort = (undistort or args.undistort), intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) |