Mercurial Hosting > traffic-intelligence
diff scripts/compute-clearmot.py @ 726:43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 07 Aug 2015 13:07:53 -0400 |
parents | e14e2101a5a9 |
children | f8e0a8ea8402 |
line wrap: on
line diff
--- a/scripts/compute-clearmot.py Fri Aug 07 01:05:01 2015 -0400 +++ b/scripts/compute-clearmot.py Fri Aug 07 13:07:53 2015 -0400 @@ -2,7 +2,8 @@ import sys, argparse from numpy import loadtxt -import moving, storage +from numpy.linalg import inv +import moving, storage, cvutils # TODO: need to trim objects to same mask ? @@ -16,9 +17,11 @@ parser.add_argument('-g', dest = 'groundTruthDatabaseFilename', help = 'name of the Sqlite database containing the ground truth', required = True) parser.add_argument('-o', dest = 'homographyFilename', help = 'name of the filename for the homography (if tracking was done using the homography)') parser.add_argument('-m', dest = 'matchingDistance', help = 'matching distance between tracker and ground truth trajectories', required = True, type = float) +parser.add_argument('--mask', dest = 'maskFilename', help = 'filename of the mask file used to define the where objects were tracked') parser.add_argument('-f', dest = 'firstInstant', help = 'first instant for measurement', required = True, type = int) parser.add_argument('-l', dest = 'lastInstant', help = 'last instant for measurement', required = True, type = int) parser.add_argument('--display', dest = 'display', help = 'display the ground truth to object matches (graphically)', action = 'store_true') +parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (for display)') args = parser.parse_args() if args.homographyFilename is not None: @@ -27,6 +30,17 @@ homography = None objects = storage.loadTrajectoriesFromSqlite(args.trackerDatabaseFilename, 'object') + +if args.maskFilename is not None: + maskObjects = [] + from matplotlib.pyplot import imread + mask = imread(args.maskFilename) + if len(mask) > 1: + mask = mask[:,:,0] + for obj in objects: + maskObjects += obj.getObjectsInMask(mask, inv(homography), 2) # TODO add option to keep object if at least one feature in mask + objects = maskObjects + annotations = storage.loadGroundTruthFromSqlite(args.groundTruthDatabaseFilename) for a in annotations: a.computeCentroidTrajectory(homography) @@ -43,7 +57,9 @@ print 'Number of mismatches: {}'.format(mme) print 'Number of false alarms.frames: {}'.format(fpt) if args.display: - print('Ground truth matches') - print(gtMatches) - print('Object matches') - print toMatches + cvutils.displayTrajectories(args.videoFilename, objects, {}, inv(homography), args.firstInstant, args.lastInstant, annotations = annotations, gtMatches = gtMatches, toMatches = toMatches)#, rescale = args.rescale, nFramesStep = args.nFramesStep, saveAllImages = args.saveAllImages, undistort = (undistort or args.undistort), intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) + + #print('Ground truth matches') + #print(gtMatches) + #print('Object matches') + #rint toMatches