annotate scripts/display-trajectories.py @ 853:95e7622b11be

added option to limit the number of loaded objects
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 22 Sep 2016 16:49:43 -0400
parents 3058e00887bc
children 753a081989e2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
30fb60428e09 corrected bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 482
diff changeset
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)
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
23 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to display', 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
24 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
25 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
26
347
7b865f4174aa updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 337
diff changeset
27 args = parser.parse_args()
236
eb4525853030 added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
28
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
29 if args.configFilename is not None: # consider there is a configuration file
536
95276d310972 renamed TrackingParameters to ProcessParameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 528
diff changeset
30 params = storage.ProcessParameters(args.configFilename)
333
c9201f6b143a moved the config parser to utils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 304
diff changeset
31 videoFilename = params.videoFilename
c9201f6b143a moved the config parser to utils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 304
diff changeset
32 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
33 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
34 homography = inv(params.homography)
5585ebd8ad61 corrected bugs for trajectory display for new code versions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 514
diff changeset
35 else:
5585ebd8ad61 corrected bugs for trajectory display for new code versions
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 514
diff changeset
36 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
37 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
38 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
39 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
40 undistort = params.undistort
333
c9201f6b143a moved the config parser to utils
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 304
diff changeset
41 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
42 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
43 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
44 undistort = False
512
81ff62a7c39f corrected bug so it can work without undistortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 509
diff changeset
45 intrinsicCameraMatrix = None
81ff62a7c39f corrected bug so it can work without undistortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 509
diff changeset
46 distortionCoefficients = []
81ff62a7c39f corrected bug so it can work without undistortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 509
diff changeset
47 undistortedImageMultiplication = None
81ff62a7c39f corrected bug so it can work without undistortion parameters
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 509
diff changeset
48 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
49
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
50 if args.configFilename is None 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
51 videoFilename = args.videoFilename
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
52 if args.configFilename is None 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
53 databaseFilename = args.databaseFilename
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
54 if args.configFilename is None and args.homographyFilename is not None:
492
30fb60428e09 corrected bug
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 482
diff changeset
55 homography = inv(loadtxt(args.homographyFilename))
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
56 if args.configFilename is None 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
57 intrinsicCameraMatrix = loadtxt(args.intrinsicCameraMatrixFilename)
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
58 if args.configFilename is None 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
59 distortionCoefficients = args.distortionCoefficients
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
60 if args.configFilename is None 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
61 undistortedImageMultiplication = args.undistortedImageMultiplication
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
62
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
63 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
64 firstFrameNum = args.firstFrameNum
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
65 if args.nObjects is not None:
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
66 nObjects = args.nObjects
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
67 else:
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
68 nObjects = 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
69
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
70 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType, nObjects)
586
ff4f0ce46ca6 modified name for loading bounding boxes (only for display)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 536
diff changeset
71 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
72 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)