annotate scripts/display-trajectories.py @ 1246:2397de73770d

dltrack saves after projecting coordinates
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 09 Feb 2024 17:47:33 -0500
parents 371c718e57d7
children 8e61ff3cd503
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
998
933670761a57 updated code to python 3 (tests pass and scripts run, but non-executed parts of code are probably still not correct)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 981
diff changeset
1 #! /usr/bin/env python3
236
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
1245
371c718e57d7 interface updates
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1028
diff changeset
4 from math import inf
236
eb4525853030 added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
5
901
753a081989e2 factorized some argument handling code
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 853
diff changeset
6 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
7 from numpy import loadtxt
236
eb4525853030 added script to display trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
8
1028
cc5cb04b04b0 major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 998
diff changeset
9 from trafficintelligence import storage, cvutils, utils
cc5cb04b04b0 major update using the trafficintelligence package name and install through pip
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 998
diff changeset
10
347
7b865f4174aa updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 337
diff changeset
11 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
12 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
13 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
14 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
15 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
16 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
17 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
18 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
19 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
20 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
21 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int)
1245
371c718e57d7 interface updates
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1028
diff changeset
22 parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to save (for image saving, no display is made)', type = int, default = inf)
385
1917db662aa7 added rescaling options to scripts play-video and display-trajectories
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 364
diff changeset
23 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
24 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
25 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
26 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
27 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
28
347
7b865f4174aa updated script to display trajectories with argparse module
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 337
diff changeset
29 args = parser.parse_args()
1246
2397de73770d dltrack saves after projecting coordinates
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1245
diff changeset
30 params, videoFilename, databaseFilename, homography, 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:
1246
2397de73770d dltrack saves after projecting coordinates
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1245
diff changeset
33 invHomography = inv(loadtxt(args.homographyFilename))
901
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
1245
371c718e57d7 interface updates
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1028
diff changeset
42 if args.lastFrameNum is not None:
371c718e57d7 interface updates
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1028
diff changeset
43 lastFrameNum = args.lastFrameNum
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
44 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
45 nObjects = args.nObjects
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
46 else:
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
47 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
48
853
95e7622b11be added option to limit the number of loaded objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 636
diff changeset
49 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
50 boundingBoxes = storage.loadBoundingBoxTableForDisplay(databaseFilename)
1245
371c718e57d7 interface updates
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents: 1028
diff changeset
51 cvutils.displayTrajectories(videoFilename, objects, boundingBoxes, invHomography, firstFrameNum, lastFrameNum, rescale = args.rescale, nFramesStep = args.nFramesStep, saveAllImages = args.saveAllImages, nZerosFilenameArg = args.nZerosFilenameArg, undistort = (undistort or args.undistort), intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication)