Mercurial Hosting > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
725:35bc5e30a53f | 726:43ae3a1af290 |
---|---|
1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
2 | 2 |
3 import sys, argparse | 3 import sys, argparse |
4 from numpy import loadtxt | 4 from numpy import loadtxt |
5 import moving, storage | 5 from numpy.linalg import inv |
6 import moving, storage, cvutils | |
6 | 7 |
7 # TODO: need to trim objects to same mask ? | 8 # TODO: need to trim objects to same mask ? |
8 | 9 |
9 parser = argparse.ArgumentParser(description='The program computes the CLEAR MOT metrics between ground truth and tracker output (in Polytrack format)', epilog='''CLEAR MOT metrics information: | 10 parser = argparse.ArgumentParser(description='The program computes the CLEAR MOT metrics between ground truth and tracker output (in Polytrack format)', epilog='''CLEAR MOT metrics information: |
10 Keni, Bernardin, and Stiefelhagen Rainer. "Evaluating multiple object tracking performance: the CLEAR MOT metrics." EURASIP Journal on Image and Video Processing 2008 (2008) | 11 Keni, Bernardin, and Stiefelhagen Rainer. "Evaluating multiple object tracking performance: the CLEAR MOT metrics." EURASIP Journal on Image and Video Processing 2008 (2008) |
14 see examples on http://www.jpjodoin.com/urbantracker/dataset.html''', formatter_class=argparse.RawDescriptionHelpFormatter) | 15 see examples on http://www.jpjodoin.com/urbantracker/dataset.html''', formatter_class=argparse.RawDescriptionHelpFormatter) |
15 parser.add_argument('-d', dest = 'trackerDatabaseFilename', help = 'name of the Sqlite database containing the tracker output', required = True) | 16 parser.add_argument('-d', dest = 'trackerDatabaseFilename', help = 'name of the Sqlite database containing the tracker output', required = True) |
16 parser.add_argument('-g', dest = 'groundTruthDatabaseFilename', help = 'name of the Sqlite database containing the ground truth', required = True) | 17 parser.add_argument('-g', dest = 'groundTruthDatabaseFilename', help = 'name of the Sqlite database containing the ground truth', required = True) |
17 parser.add_argument('-o', dest = 'homographyFilename', help = 'name of the filename for the homography (if tracking was done using the homography)') | 18 parser.add_argument('-o', dest = 'homographyFilename', help = 'name of the filename for the homography (if tracking was done using the homography)') |
18 parser.add_argument('-m', dest = 'matchingDistance', help = 'matching distance between tracker and ground truth trajectories', required = True, type = float) | 19 parser.add_argument('-m', dest = 'matchingDistance', help = 'matching distance between tracker and ground truth trajectories', required = True, type = float) |
20 parser.add_argument('--mask', dest = 'maskFilename', help = 'filename of the mask file used to define the where objects were tracked') | |
19 parser.add_argument('-f', dest = 'firstInstant', help = 'first instant for measurement', required = True, type = int) | 21 parser.add_argument('-f', dest = 'firstInstant', help = 'first instant for measurement', required = True, type = int) |
20 parser.add_argument('-l', dest = 'lastInstant', help = 'last instant for measurement', required = True, type = int) | 22 parser.add_argument('-l', dest = 'lastInstant', help = 'last instant for measurement', required = True, type = int) |
21 parser.add_argument('--display', dest = 'display', help = 'display the ground truth to object matches (graphically)', action = 'store_true') | 23 parser.add_argument('--display', dest = 'display', help = 'display the ground truth to object matches (graphically)', action = 'store_true') |
24 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (for display)') | |
22 args = parser.parse_args() | 25 args = parser.parse_args() |
23 | 26 |
24 if args.homographyFilename is not None: | 27 if args.homographyFilename is not None: |
25 homography = loadtxt(args.homographyFilename) | 28 homography = loadtxt(args.homographyFilename) |
26 else: | 29 else: |
27 homography = None | 30 homography = None |
28 | 31 |
29 objects = storage.loadTrajectoriesFromSqlite(args.trackerDatabaseFilename, 'object') | 32 objects = storage.loadTrajectoriesFromSqlite(args.trackerDatabaseFilename, 'object') |
33 | |
34 if args.maskFilename is not None: | |
35 maskObjects = [] | |
36 from matplotlib.pyplot import imread | |
37 mask = imread(args.maskFilename) | |
38 if len(mask) > 1: | |
39 mask = mask[:,:,0] | |
40 for obj in objects: | |
41 maskObjects += obj.getObjectsInMask(mask, inv(homography), 2) # TODO add option to keep object if at least one feature in mask | |
42 objects = maskObjects | |
43 | |
30 annotations = storage.loadGroundTruthFromSqlite(args.groundTruthDatabaseFilename) | 44 annotations = storage.loadGroundTruthFromSqlite(args.groundTruthDatabaseFilename) |
31 for a in annotations: | 45 for a in annotations: |
32 a.computeCentroidTrajectory(homography) | 46 a.computeCentroidTrajectory(homography) |
33 | 47 |
34 if args.display: | 48 if args.display: |
41 print 'MOTA: {}'.format(mota) | 55 print 'MOTA: {}'.format(mota) |
42 print 'Number of missed objects.frames: {}'.format(mt) | 56 print 'Number of missed objects.frames: {}'.format(mt) |
43 print 'Number of mismatches: {}'.format(mme) | 57 print 'Number of mismatches: {}'.format(mme) |
44 print 'Number of false alarms.frames: {}'.format(fpt) | 58 print 'Number of false alarms.frames: {}'.format(fpt) |
45 if args.display: | 59 if args.display: |
46 print('Ground truth matches') | 60 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) |
47 print(gtMatches) | 61 |
48 print('Object matches') | 62 #print('Ground truth matches') |
49 print toMatches | 63 #print(gtMatches) |
64 #print('Object matches') | |
65 #rint toMatches |