diff python/moving.py @ 592:985a3021cff2

first match table implementation
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 05 Dec 2014 17:50:16 -0500
parents 0fa73cbe9fdb
children e2a873e08568
line wrap: on
line diff
--- a/python/moving.py	Fri Dec 05 17:00:37 2014 -0500
+++ b/python/moving.py	Fri Dec 05 17:50:16 2014 -0500
@@ -1307,14 +1307,37 @@
     def matches(self, obj, instant, matchingDistance):
         '''Indicates if the annotation matches obj (MovingObject)
         with threshold matchingDistance'''
-        return True
+        d = Point.distanceNorm2(self.getPositionAtInstant(instant), obj.getPositionAtInstant(instant))
+        return d<matchingDistance, d
 
-def matchingGroundTruthToTracker(objects, annotations, matchingDistance):
+def matchingGroundTruthToTracker(objects, annotations, matchingDistance, firstInstant, lastInstant):
     '''Returns a matching of tracker output (objects) to ground truth (annnotations)
 
     objects and annotations are supposed to in the same space
     current implementation is BBAnnotations (bounding boxes)
-    mathingDistance is threshold on matching between annotation and object'''
+    mathingDistance is threshold on matching between annotation and object
+
+    Output is list of 
+    [frame number, ground truth id, tracker object id, distance]
+    where tracker object id is None if no matching was found'''
+    
+    matchTable = []
+    for t in xrange(firstInstant, lastInstant+1):
+        for a in annotations:
+            if a.existsAtInstant(t):
+                minDist = float('inf')
+                matchingObject = None
+                for o in objects:
+                    if o.existsAtInstant(t):
+                        match, d = a.matches(o, t, matchingDistance)
+                        if match and d<minDist:
+                            minDist = d
+                            matchingObject = o
+                if matchingObject == None:
+                    matchTable.append([t, a.getNum(), None, minDist])
+                else:
+                    matchTable.append([t, a.getNum(), matchingObject.getNum(), minDist])
+    return matchTable
 
 def plotRoadUsers(objects, colors):
     '''Colors is a PlottingPropertyValues instance'''