diff scripts/display-trajectories.py @ 509:935430b1d408

corrected mask bug in feature tracking, updated display-trajectories to display on undistorted image
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 23 May 2014 16:27:26 -0400
parents 30fb60428e09
children 81ff62a7c39f
line wrap: on
line diff
--- a/scripts/display-trajectories.py	Fri May 23 10:35:51 2014 -0400
+++ b/scripts/display-trajectories.py	Fri May 23 16:27:26 2014 -0400
@@ -13,32 +13,49 @@
 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file')
 parser.add_argument('-t', dest = 'trajectoryType', help = 'type of trajectories to display', choices = ['feature', 'object'], default = 'feature')
 parser.add_argument('-o', dest = 'homographyFilename', help = 'name of the image to world homography file')
-parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', default = 0, type = int)
+parser.add_argument('--intrinsic', dest = 'intrinsicCameraMatrixFilename', help = 'name of the intrinsic camera file')
+parser.add_argument('--distortion-coefficients', dest = 'distortionCoefficients', help = 'distortion coefficients', nargs = '*', type = float)
+parser.add_argument('--undistorted-multiplication', dest = 'undistortedImageMultiplication', help = 'undistorted image multiplication', type = float)
+parser.add_argument('-u', dest = 'undistort', help = 'undistort the video (because features have been extracted that way)', action = 'store_true')
+parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int)
 parser.add_argument('-r', dest = 'rescale', help = 'rescaling factor for the displayed image', default = 1., type = float)
 parser.add_argument('-s', dest = 'nFramesStep', help = 'number of frames between each display', default = 1, type = int)
 parser.add_argument('--save-images', dest = 'saveAllImages', help = 'save all images', action = 'store_true')
-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)
+parser.add_argument('--last-frame', dest = 'lastFrameNum', help = 'number of last frame number to save (for image saving, no display is made)', type = int)
 
 args = parser.parse_args()
 
-homography = None
 if args.configFilename: # consider there is a configuration file
-    params = utils.TrackingParameters()
-    params.loadConfigFile(args.configFilename)
+    params = storage.TrackingParameters(args.configFilename)
     videoFilename = params.videoFilename
     databaseFilename = params.databaseFilename
-    homography = inv(loadtxt(params.homographyFilename))
+    homography = inv(params.homography)
+    intrinsicCameraMatrix = params.intrinsicCameraMatrix
+    distortionCoefficients = params.distortionCoefficients
+    undistortedImageMultiplication = params.undistortedImageMultiplication
+    undistort = params.undistort
     firstFrameNum = params.firstFrameNum
+else:
+    homography = None
+    undistort = False
+    
 
-if args.videoFilename != None:
+if not args.configFilename or args.videoFilename != None:
     videoFilename = args.videoFilename
-if args.databaseFilename != None:
+if not args.configFilename or args.databaseFilename != None:
     databaseFilename = args.databaseFilename
-if args.homographyFilename != None:
+if not args.configFilename or args.homographyFilename != None:
     homography = inv(loadtxt(args.homographyFilename))            
-if args.firstFrameNum != None:
+if not args.configFilename or args.intrinsicCameraMatrixFilename != None:
+    intrinsicCameraMatrix = loadtxt(args.intrinsicCameraMatrixFilename)
+if not args.configFilename or args.distortionCoefficients != None:
+    distortionCoefficients = args.distortionCoefficients
+if not args.configFilename or args.undistortedImageMultiplication != None:
+    undistortedImageMultiplication = args.undistortedImageMultiplication
+if not args.configFilename or args.firstFrameNum != None:
     firstFrameNum = args.firstFrameNum
 
+
 objects = storage.loadTrajectoriesFromSqlite(databaseFilename, args.trajectoryType)
 boundingBoxes = storage.loadBoundingBoxTable(databaseFilename)
-cvutils.displayTrajectories(videoFilename, objects, boundingBoxes, homography, firstFrameNum, args.lastFrameNum, rescale = args.rescale, nFramesStep = args.nFramesStep, saveAllImages = args.saveAllImages)
+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)