Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/display-trajectories.py @ 1245:371c718e57d7
interface updates
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 08 Feb 2024 16:10:54 -0500 |
| parents | cc5cb04b04b0 |
| children | 2397de73770d |
comparison
equal
deleted
inserted
replaced
| 1244:00b71da2baac | 1245:371c718e57d7 |
|---|---|
| 1 #! /usr/bin/env python3 | 1 #! /usr/bin/env python3 |
| 2 | 2 |
| 3 import sys, argparse | 3 import sys, argparse |
| 4 from math import inf | |
| 4 | 5 |
| 5 from numpy.linalg import inv | 6 from numpy.linalg import inv |
| 6 from numpy import loadtxt | 7 from numpy import loadtxt |
| 7 | 8 |
| 8 from trafficintelligence import storage, cvutils, utils | 9 from trafficintelligence import storage, cvutils, utils |
| 16 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file') | 17 parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file') |
| 17 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float) | 18 parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float) |
| 18 parser.add_argument('--undistorted-multiplication', dest = 'undistortedImageMultiplication', help = 'undistorted image multiplication', type = float) | 19 parser.add_argument('--undistorted-multiplication', dest = 'undistortedImageMultiplication', help = 'undistorted image multiplication', type = float) |
| 19 parser.add_argument('-u', dest = 'undistort', help = 'undistort the video (because features have been extracted that way)', action = 'store_true') | 20 parser.add_argument('-u', dest = 'undistort', help = 'undistort the video (because features have been extracted that way)', action = 'store_true') |
| 20 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int) | 21 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int) |
| 21 parser.add_argument('-l', dest = 'lastFrameNum', help = 'number of last frame number to save (for image saving, no display is made)', type = int) | 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) |
| 22 parser.add_argument('-r', dest = 'rescale', help = 'rescaling factor for the displayed image', default = 1., type = float) | 23 parser.add_argument('-r', dest = 'rescale', help = 'rescaling factor for the displayed image', default = 1., type = float) |
| 23 parser.add_argument('-s', dest = 'nFramesStep', help = 'number of frames between each display', default = 1, type = int) | 24 parser.add_argument('-s', dest = 'nFramesStep', help = 'number of frames between each display', default = 1, type = int) |
| 24 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to display', type = int) | 25 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to display', type = int) |
| 25 parser.add_argument('--save-images', dest = 'saveAllImages', help = 'save all images', action = 'store_true') | 26 parser.add_argument('--save-images', dest = 'saveAllImages', help = 'save all images', action = 'store_true') |
| 26 parser.add_argument('--nzeros', dest = 'nZerosFilenameArg', help = 'number of digits in filenames', type = int) | 27 parser.add_argument('--nzeros', dest = 'nZerosFilenameArg', help = 'number of digits in filenames', type = int) |
| 27 | 28 |
| 28 args = parser.parse_args() | 29 args = parser.parse_args() |
| 29 | |
| 30 params, videoFilename, databaseFilename, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args) | 30 params, videoFilename, databaseFilename, invHomography, intrinsicCameraMatrix, distortionCoefficients, undistortedImageMultiplication, undistort, firstFrameNum = storage.processVideoArguments(args) |
| 31 | 31 |
| 32 if args.homographyFilename is not None: | 32 if args.homographyFilename is not None: |
| 33 invHomography = inv(loadtxt(args.homographyFilename)) | 33 invHomography = inv(loadtxt(args.homographyFilename)) |
| 34 if args.intrinsicCameraMatrixFilename is not None: | 34 if args.intrinsicCameraMatrixFilename is not None: |
| 37 distortionCoefficients = args.distortionCoefficients | 37 distortionCoefficients = args.distortionCoefficients |
| 38 if args.undistortedImageMultiplication is not None: | 38 if args.undistortedImageMultiplication is not None: |
| 39 undistortedImageMultiplication = args.undistortedImageMultiplication | 39 undistortedImageMultiplication = args.undistortedImageMultiplication |
| 40 if args.firstFrameNum is not None: | 40 if args.firstFrameNum is not None: |
| 41 firstFrameNum = args.firstFrameNum | 41 firstFrameNum = args.firstFrameNum |
| 42 if args.lastFrameNum is not None: | |
| 43 lastFrameNum = args.lastFrameNum | |
| 42 if args.nObjects is not None: | 44 if args.nObjects is not None: |
| 43 nObjects = args.nObjects | 45 nObjects = args.nObjects |
| 44 else: | 46 else: |
| 45 nObjects = None | 47 nObjects = None |
| 46 | 48 |
| 47 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType, nObjects) | 49 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType, nObjects) |
| 48 boundingBoxes = storage.loadBoundingBoxTableForDisplay(databaseFilename) | 50 boundingBoxes = storage.loadBoundingBoxTableForDisplay(databaseFilename) |
| 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) | 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) |
