changeset 785:3aa6102ccc12 dev

addressed issues with ground truth annotations shifted in time
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 03 Mar 2016 17:01:30 -0500
parents 30bd0f2223b7
children 1f2b2d1f4fbf
files python/moving.py scripts/compute-clearmot.py
diffstat 2 files changed, 30 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/python/moving.py	Thu Mar 03 14:31:13 2016 -0500
+++ b/python/moving.py	Thu Mar 03 17:01:30 2016 -0500
@@ -61,6 +61,10 @@
         '''Indicates if the temporal interval of self is comprised in interval2'''
         return (self.first >= interval2.first) and (self.last <= interval2.last)
 
+    def shift(self, offset):
+        self.first += offset
+        self.last += offset
+
     @classmethod
     def union(cls, interval1, interval2):
         '''Smallest interval comprising self and interval2'''
@@ -174,6 +178,9 @@
     def commonTimeInterval(self, obj2):
         return TimeInterval.intersection(self.getTimeInterval(), obj2.getTimeInterval())
 
+    def shiftTimeInterval(self, offset):
+        self.timeInterval.shift(offset)
+
 class Point(object):
     def __init__(self, x, y):
         self.x = x
--- a/scripts/compute-clearmot.py	Thu Mar 03 14:31:13 2016 -0500
+++ b/scripts/compute-clearmot.py	Thu Mar 03 17:01:30 2016 -0500
@@ -20,6 +20,8 @@
 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('--offset', dest = 'nFramesOffsetAnnotations', help = 'number of frames to offset the ground truth annotations', type = int)
+parser.add_argument('--displayOffset', dest = 'nFramesOffsetDisplay', help = 'number of frames to offset annotations and objects for display', 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()
@@ -45,6 +47,10 @@
 for a in annotations:
     a.computeCentroidTrajectory(homography)
 
+if args.nFramesOffsetAnnotations is not None:
+    for a in annotations:
+        a.shiftTimeInterval(args.nFramesOffsetAnnotations)
+
 if args.display:
     motp, mota, mt, mme, fpt, gt, gtMatches, toMatches = moving.computeClearMOT(annotations, objects, args.matchingDistance, args.firstInstant, args.lastInstant, True)
 else:
@@ -56,8 +62,24 @@
 print 'Number of missed objects.frames: {}'.format(mt)
 print 'Number of mismatches: {}'.format(mme)
 print 'Number of false alarms.frames: {}'.format(fpt)
+
+def shiftMatches(matches, offset):
+    shifted = {}
+    for k in matches:
+        shifted[k] = {t+offset:v for t, v in matches[k].iteritems()}
+    return shifted
+
 if args.display:
-    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)
+    if args.nFramesOffsetDisplay is not None:
+        firstInstant = args.firstInstant+args.nFramesOffsetDisplay
+        lastInstant = args.lastInstant+args.nFramesOffsetDisplay
+        for a in annotations:
+            a.shiftTimeInterval(args.nFramesOffsetDisplay)
+        for o in objects:
+            o.shiftTimeInterval(args.nFramesOffsetDisplay)
+        gtMatches = shiftMatches(gtMatches, args.nFramesOffsetDisplay)
+        toMatches = shiftMatches(toMatches, args.nFramesOffsetDisplay)
+    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)
 
     #print('Ground truth matches')
     #print(gtMatches)