comparison scripts/compute-clearmot.py @ 729:dad99b86a104 dev

merge with default
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 10 Aug 2015 17:52:19 -0400
parents 43ae3a1af290
children f8e0a8ea8402
comparison
equal deleted inserted replaced
728:4e89341edd29 729:dad99b86a104
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)
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)')
21 args = parser.parse_args() 25 args = parser.parse_args()
22 26
23 if args.homographyFilename is not None: 27 if args.homographyFilename is not None:
24 homography = loadtxt(args.homographyFilename) 28 homography = loadtxt(args.homographyFilename)
25 else: 29 else:
26 homography = None 30 homography = None
27 31
28 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
29 annotations = storage.loadGroundTruthFromSqlite(args.groundTruthDatabaseFilename) 44 annotations = storage.loadGroundTruthFromSqlite(args.groundTruthDatabaseFilename)
30 for a in annotations: 45 for a in annotations:
31 a.computeCentroidTrajectory(homography) 46 a.computeCentroidTrajectory(homography)
32 47
33 motp, mota, mt, mme, fpt, gt = moving.computeClearMOT(annotations, objects, args.matchingDistance, args.firstInstant, args.lastInstant) 48 if args.display:
49 motp, mota, mt, mme, fpt, gt, gtMatches, toMatches = moving.computeClearMOT(annotations, objects, args.matchingDistance, args.firstInstant, args.lastInstant, True)
50 else:
51 motp, mota, mt, mme, fpt, gt = moving.computeClearMOT(annotations, objects, args.matchingDistance, args.firstInstant, args.lastInstant)
52
34 53
35 print 'MOTP: {}'.format(motp) 54 print 'MOTP: {}'.format(motp)
36 print 'MOTA: {}'.format(mota) 55 print 'MOTA: {}'.format(mota)
37 print 'Number of missed objects.frames: {}'.format(mt) 56 print 'Number of missed objects.frames: {}'.format(mt)
38 print 'Number of mismatches: {}'.format(mme) 57 print 'Number of mismatches: {}'.format(mme)
39 print 'Number of false alarms.frames: {}'.format(fpt) 58 print 'Number of false alarms.frames: {}'.format(fpt)
59 if args.display:
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)
61
62 #print('Ground truth matches')
63 #print(gtMatches)
64 #print('Object matches')
65 #rint toMatches