annotate scripts/display-trajectories.py @ 981:c3e690c5536e

corrected bug in display trajectories
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 27 Feb 2018 15:24:57 -0500
parents c69a8defe5c3
children 933670761a57
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
901
753a081989e2 factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 853
diff changeset
7 from numpy.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')
902
c69a8defe5c3 changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 901
diff changeset
12 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file (overrides the configuration file)')
c69a8defe5c3 changed workflow of classify objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 901
diff changeset
13 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (overrides the configuration file)')
347
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)
901
753a081989e2 factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 853
diff changeset
21 parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to save (for image saving, no display is made)', type = int)
385
1917db662aa7 added rescaling options to scripts play-video and display-trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 364
diff changeset
22 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
23 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
24 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
25 parser.add_argument('--save-images', dest = 'saveAllImages', help = 'save all images', action = 'store_true')
981
c3e690c5536e corrected bug in display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 902
diff changeset
26 parser.add_argument('--nzeros', dest = 'nZerosFilenameArg', help = 'number of digits in filenames', type = int)
304
20f9cd972dde added capability to parse cfg file for display-trajectories.py
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 239
diff changeset
27
347
7b865f4174aa updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 337
diff changeset
28 args = parser.parse_args()
236
eb4525853030 added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
29
901
753a081989e2 factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 853
diff changeset
30 params, videoFilename, databaseFilename, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args)
364
a50a69e04c2a script modification so that command line arguments take precedence over config file
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 347
diff changeset
31
901
753a081989e2 factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 853
diff changeset
32 if args.homographyFilename is not None:
753a081989e2 factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 853
diff changeset
33 invHomography = inv(loadtxt(args.homographyFilename))
753a081989e2 factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 853
diff changeset
34 if 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
35 intrinsicCameraMatrix = loadtxt(args.intrinsicCameraMatrixFilename)
901
753a081989e2 factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 853
diff changeset
36 if 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
37 distortionCoefficients = args.distortionCoefficients
901
753a081989e2 factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 853
diff changeset
38 if 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
39 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
40 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
41 firstFrameNum = args.firstFrameNum
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
42 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
43 nObjects = args.nObjects
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
44 else:
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
45 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
46
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
47 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
48 boundingBoxes = storage.loadBoundingBoxTableForDisplay(databaseFilename)
981
c3e690c5536e corrected bug in display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 902
diff changeset
49 cvutils.displayTrajectories(videoFilename, objects, boundingBoxes, invHomography, firstFrameNum, args.lastFrameNum, rescale = args.rescale, nFramesStep = args.nFramesStep, saveAllImages = args.saveAllImages, nZerosFilenameArg = args.nZerosFilenameArg, undistort = (undistort or args.undistort), intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication)