Mercurial Hosting > traffic-intelligence
comparison scripts/display-trajectories.py @ 513:dbf4b83afbb9
pulled in and merged the new functionalities to deal with camera distortion (eg GoPro cameras)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 04 Jun 2014 10:57:09 -0400 |
parents | 81ff62a7c39f |
children | 1ba618fb0f70 |
comparison
equal
deleted
inserted
replaced
505:35c99776e593 | 513:dbf4b83afbb9 |
---|---|
11 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') | 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') | 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') | 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') | 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') | 15 parser.add_argument('-o', dest = 'homographyFilename', help = 'name of the image to world homography file') |
16 parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', default = 0, type = int) | 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) | |
17 parser.add_argument('-r', dest = 'rescale', help = 'rescaling factor for the displayed image', default = 1., type = float) | 21 parser.add_argument('-r', dest = 'rescale', help = 'rescaling factor for the displayed image', default = 1., type = float) |
18 parser.add_argument('-s', dest = 'nFramesStep', help = 'number of frames between each display', default = 1, type = int) | 22 parser.add_argument('-s', dest = 'nFramesStep', help = 'number of frames between each display', default = 1, type = int) |
19 parser.add_argument('--save-images', dest = 'saveAllImages', help = 'save all images', action = 'store_true') | 23 parser.add_argument('--save-images', dest = 'saveAllImages', help = 'save all images', action = 'store_true') |
20 parser.add_argument('--last-frame', dest = 'lastFrameNum', help = 'number of last frame number to save (for image saving, no display is made)', default = None, type = int) | 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) |
21 | 25 |
22 args = parser.parse_args() | 26 args = parser.parse_args() |
23 | 27 |
24 homography = None | |
25 if args.configFilename: # consider there is a configuration file | 28 if args.configFilename: # consider there is a configuration file |
26 params = utils.TrackingParameters() | 29 params = storage.TrackingParameters(args.configFilename) |
27 params.loadConfigFile(args.configFilename) | |
28 videoFilename = params.videoFilename | 30 videoFilename = params.videoFilename |
29 databaseFilename = params.databaseFilename | 31 databaseFilename = params.databaseFilename |
30 homography = inv(loadtxt(params.homographyFilename)) | 32 homography = inv(params.homography) |
33 intrinsicCameraMatrix = params.intrinsicCameraMatrix | |
34 distortionCoefficients = params.distortionCoefficients | |
35 undistortedImageMultiplication = params.undistortedImageMultiplication | |
36 undistort = params.undistort | |
31 firstFrameNum = params.firstFrameNum | 37 firstFrameNum = params.firstFrameNum |
38 else: | |
39 homography = None | |
40 undistort = False | |
41 intrinsicCameraMatrix = None | |
42 distortionCoefficients = [] | |
43 undistortedImageMultiplication = None | |
44 firstFrameNum = 0 | |
32 | 45 |
33 if args.videoFilename != None: | 46 if not args.configFilename and args.videoFilename != None: |
34 videoFilename = args.videoFilename | 47 videoFilename = args.videoFilename |
35 if args.databaseFilename != None: | 48 if not args.configFilename and args.databaseFilename != None: |
36 databaseFilename = args.databaseFilename | 49 databaseFilename = args.databaseFilename |
37 if args.homographyFilename != None: | 50 if not args.configFilename and args.homographyFilename != None: |
38 homography = inv(loadtxt(args.homographyFilename)) | 51 homography = inv(loadtxt(args.homographyFilename)) |
39 if args.firstFrameNum != None: | 52 if not args.configFilename and args.intrinsicCameraMatrixFilename != None: |
53 intrinsicCameraMatrix = loadtxt(args.intrinsicCameraMatrixFilename) | |
54 if not args.configFilename and args.distortionCoefficients != None: | |
55 distortionCoefficients = args.distortionCoefficients | |
56 if not args.configFilename and args.undistortedImageMultiplication != None: | |
57 undistortedImageMultiplication = args.undistortedImageMultiplication | |
58 if not args.configFilename and args.firstFrameNum != None: | |
40 firstFrameNum = args.firstFrameNum | 59 firstFrameNum = args.firstFrameNum |
60 | |
41 | 61 |
42 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType) | 62 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType) |
43 boundingBoxes = storage.loadBoundingBoxTable(databaseFilename) | 63 boundingBoxes = storage.loadBoundingBoxTable(databaseFilename) |
44 cvutils.displayTrajectories(videoFilename, objects, boundingBoxes, homography, firstFrameNum, args.lastFrameNum, rescale = args.rescale, nFramesStep = args.nFramesStep, saveAllImages = args.saveAllImages) | 64 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) |