Mercurial Hosting > traffic-intelligence
annotate scripts/compute-clearmot.py @ 816:0b03218cd008
merged
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sat, 18 Jun 2016 14:26:50 -0400 |
parents | 3aa6102ccc12 |
children | f6790357f53b |
rev | line source |
---|---|
591
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
1 #! /usr/bin/env python |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
2 |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
3 import sys, argparse |
592
985a3021cff2
first match table implementation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
591
diff
changeset
|
4 from numpy import loadtxt |
726
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
5 from numpy.linalg import inv |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
6 import moving, storage, cvutils |
591
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
7 |
592
985a3021cff2
first match table implementation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
591
diff
changeset
|
8 # TODO: need to trim objects to same mask ? |
591
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
9 |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
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: |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
11 Keni, Bernardin, and Stiefelhagen Rainer. "Evaluating multiple object tracking performance: the CLEAR MOT metrics." EURASIP Journal on Image and Video Processing 2008 (2008) |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
12 |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
13 Polytrack format: |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
14 JP. Jodoin\'s MSc thesis (in french) |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
15 see examples on http://www.jpjodoin.com/urbantracker/dataset.html''', formatter_class=argparse.RawDescriptionHelpFormatter) |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
16 parser.add_argument('-d', dest = 'trackerDatabaseFilename', help = 'name of the Sqlite database containing the tracker output', required = True) |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
17 parser.add_argument('-g', dest = 'groundTruthDatabaseFilename', help = 'name of the Sqlite database containing the ground truth', required = True) |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
18 parser.add_argument('-o', dest = 'homographyFilename', help = 'name of the filename for the homography (if tracking was done using the homography)') |
594
9e39cd95e017
first implementation of CLEAR MOT (needs formal tests)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
593
diff
changeset
|
19 parser.add_argument('-m', dest = 'matchingDistance', help = 'matching distance between tracker and ground truth trajectories', required = True, type = float) |
726
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
20 parser.add_argument('--mask', dest = 'maskFilename', help = 'filename of the mask file used to define the where objects were tracked') |
594
9e39cd95e017
first implementation of CLEAR MOT (needs formal tests)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
593
diff
changeset
|
21 parser.add_argument('-f', dest = 'firstInstant', help = 'first instant for measurement', required = True, type = int) |
9e39cd95e017
first implementation of CLEAR MOT (needs formal tests)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
593
diff
changeset
|
22 parser.add_argument('-l', dest = 'lastInstant', help = 'last instant for measurement', required = True, type = int) |
785
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
23 parser.add_argument('--offset', dest = 'nFramesOffsetAnnotations', help = 'number of frames to offset the ground truth annotations', type = int) |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
24 parser.add_argument('--displayOffset', dest = 'nFramesOffsetDisplay', help = 'number of frames to offset annotations and objects for display', type = int) |
723
e14e2101a5a9
returns detailed matching information for clear mot
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
25 parser.add_argument('--display', dest = 'display', help = 'display the ground truth to object matches (graphically)', action = 'store_true') |
726
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
26 parser.add_argument('-i', dest = 'videoFilename', help = 'name of the video file (for display)') |
591
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
27 args = parser.parse_args() |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
28 |
636
3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
595
diff
changeset
|
29 if args.homographyFilename is not None: |
591
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
30 homography = loadtxt(args.homographyFilename) |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
31 else: |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
32 homography = None |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
33 |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
34 objects = storage.loadTrajectoriesFromSqlite(args.trackerDatabaseFilename, 'object') |
726
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
35 |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
36 if args.maskFilename is not None: |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
37 maskObjects = [] |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
38 from matplotlib.pyplot import imread |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
39 mask = imread(args.maskFilename) |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
40 if len(mask) > 1: |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
41 mask = mask[:,:,0] |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
42 for obj in objects: |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
43 maskObjects += obj.getObjectsInMask(mask, inv(homography), 2) # TODO add option to keep object if at least one feature in mask |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
44 objects = maskObjects |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
45 |
768
f8e0a8ea8402
updated the bounding box code (the name so that it is general for ground truth and UT)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
726
diff
changeset
|
46 annotations = storage.loadBBMovingObjectsFromSqlite(args.groundTruthDatabaseFilename) |
591
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
47 for a in annotations: |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
48 a.computeCentroidTrajectory(homography) |
aded6c1c2ebd
added framework script and function to compute matchings
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff
changeset
|
49 |
785
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
50 if args.nFramesOffsetAnnotations is not None: |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
51 for a in annotations: |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
52 a.shiftTimeInterval(args.nFramesOffsetAnnotations) |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
53 |
723
e14e2101a5a9
returns detailed matching information for clear mot
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
54 if args.display: |
e14e2101a5a9
returns detailed matching information for clear mot
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
55 motp, mota, mt, mme, fpt, gt, gtMatches, toMatches = moving.computeClearMOT(annotations, objects, args.matchingDistance, args.firstInstant, args.lastInstant, True) |
e14e2101a5a9
returns detailed matching information for clear mot
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
56 else: |
e14e2101a5a9
returns detailed matching information for clear mot
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
57 motp, mota, mt, mme, fpt, gt = moving.computeClearMOT(annotations, objects, args.matchingDistance, args.firstInstant, args.lastInstant) |
e14e2101a5a9
returns detailed matching information for clear mot
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
58 |
592
985a3021cff2
first match table implementation
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
591
diff
changeset
|
59 |
594
9e39cd95e017
first implementation of CLEAR MOT (needs formal tests)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
593
diff
changeset
|
60 print 'MOTP: {}'.format(motp) |
9e39cd95e017
first implementation of CLEAR MOT (needs formal tests)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
593
diff
changeset
|
61 print 'MOTA: {}'.format(mota) |
9e39cd95e017
first implementation of CLEAR MOT (needs formal tests)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
593
diff
changeset
|
62 print 'Number of missed objects.frames: {}'.format(mt) |
9e39cd95e017
first implementation of CLEAR MOT (needs formal tests)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
593
diff
changeset
|
63 print 'Number of mismatches: {}'.format(mme) |
9e39cd95e017
first implementation of CLEAR MOT (needs formal tests)
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
593
diff
changeset
|
64 print 'Number of false alarms.frames: {}'.format(fpt) |
785
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
65 |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
66 def shiftMatches(matches, offset): |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
67 shifted = {} |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
68 for k in matches: |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
69 shifted[k] = {t+offset:v for t, v in matches[k].iteritems()} |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
70 return shifted |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
71 |
723
e14e2101a5a9
returns detailed matching information for clear mot
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
636
diff
changeset
|
72 if args.display: |
785
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
73 if args.nFramesOffsetDisplay is not None: |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
74 firstInstant = args.firstInstant+args.nFramesOffsetDisplay |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
75 lastInstant = args.lastInstant+args.nFramesOffsetDisplay |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
76 for a in annotations: |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
77 a.shiftTimeInterval(args.nFramesOffsetDisplay) |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
78 for o in objects: |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
79 o.shiftTimeInterval(args.nFramesOffsetDisplay) |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
80 gtMatches = shiftMatches(gtMatches, args.nFramesOffsetDisplay) |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
81 toMatches = shiftMatches(toMatches, args.nFramesOffsetDisplay) |
3aa6102ccc12
addressed issues with ground truth annotations shifted in time
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
768
diff
changeset
|
82 cvutils.displayTrajectories(args.videoFilename, objects, {}, inv(homography), firstInstant, 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) |
726
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
83 |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
84 #print('Ground truth matches') |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
85 #print(gtMatches) |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
86 #print('Object matches') |
43ae3a1af290
added functionality to display matchings between ground truth and tracked objects
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
723
diff
changeset
|
87 #rint toMatches |