Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/display-trajectories.py @ 614:5e09583275a4
Merged Nicolas/trafficintelligence into default
| author | Mohamed Gomaa <eng.m.gom3a@gmail.com> |
|---|---|
| date | Fri, 05 Dec 2014 12:13:53 -0500 |
| parents | ff4f0ce46ca6 |
| children | 3058e00887bc |
comparison
equal
deleted
inserted
replaced
| 598:11f96bd08552 | 614:5e09583275a4 |
|---|---|
| 1 #! /usr/bin/env python | |
| 2 | |
| 3 import sys, argparse | |
| 4 | |
| 5 import storage, cvutils, utils | |
| 6 | |
| 7 from numpy.linalg.linalg import inv | |
| 8 from numpy import loadtxt | |
| 9 | |
| 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.') | |
| 11 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') | |
| 12 parser.add_argument('-d', dest = 'databaseFilename', help = 'name of the Sqlite database file') | |
| 13 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file') | |
| 14 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to display', choices = ['feature', 'object'], default = 'feature') | |
| 15 parser.add_argument('-o', dest = 'homographyFilename', help = 'name of the image to world homography file') | |
| 16 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('--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('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int) | |
| 21 parser.add_argument('-r', dest = 'rescale', help = 'rescaling factor for the displayed image', default = 1., type = float) | |
| 22 parser.add_argument('-s', dest = 'nFramesStep', help = 'number of frames between each display', default = 1, type = int) | |
| 23 parser.add_argument('--save-images', dest = 'saveAllImages', help = 'save all images', action = 'store_true') | |
| 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) | |
| 25 | |
| 26 args = parser.parse_args() | |
| 27 | |
| 28 if args.configFilename: # consider there is a configuration file | |
| 29 params = storage.ProcessParameters(args.configFilename) | |
| 30 videoFilename = params.videoFilename | |
| 31 databaseFilename = params.databaseFilename | |
| 32 if params.homography != None: | |
| 33 homography = inv(params.homography) | |
| 34 else: | |
| 35 homography = None | |
| 36 intrinsicCameraMatrix = params.intrinsicCameraMatrix | |
| 37 distortionCoefficients = params.distortionCoefficients | |
| 38 undistortedImageMultiplication = params.undistortedImageMultiplication | |
| 39 undistort = params.undistort | |
| 40 firstFrameNum = params.firstFrameNum | |
| 41 else: | |
| 42 homography = None | |
| 43 undistort = False | |
| 44 intrinsicCameraMatrix = None | |
| 45 distortionCoefficients = [] | |
| 46 undistortedImageMultiplication = None | |
| 47 firstFrameNum = 0 | |
| 48 | |
| 49 if not args.configFilename and args.videoFilename != None: | |
| 50 videoFilename = args.videoFilename | |
| 51 if not args.configFilename and args.databaseFilename != None: | |
| 52 databaseFilename = args.databaseFilename | |
| 53 if not args.configFilename and args.homographyFilename != None: | |
| 54 homography = inv(loadtxt(args.homographyFilename)) | |
| 55 if not args.configFilename and args.intrinsicCameraMatrixFilename != None: | |
| 56 intrinsicCameraMatrix = loadtxt(args.intrinsicCameraMatrixFilename) | |
| 57 if not args.configFilename and args.distortionCoefficients != None: | |
| 58 distortionCoefficients = args.distortionCoefficients | |
| 59 if not args.configFilename and args.undistortedImageMultiplication != None: | |
| 60 undistortedImageMultiplication = args.undistortedImageMultiplication | |
| 61 if args.firstFrameNum != None: | |
| 62 firstFrameNum = args.firstFrameNum | |
| 63 | |
| 64 | |
| 65 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType) | |
| 66 boundingBoxes = storage.loadBoundingBoxTableForDisplay(databaseFilename) | |
| 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) |
