diff python/moving.py @ 345:fa64b2e3a64f

added simple classification based on speed
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 25 Jun 2013 23:43:32 -0400
parents 74e437ab5f11
children e5fe0e6d48a1
line wrap: on
line diff
--- a/python/moving.py	Fri Jun 21 17:32:57 2013 -0400
+++ b/python/moving.py	Tue Jun 25 23:43:32 2013 -0400
@@ -5,6 +5,7 @@
 import cvutils
 
 from math import sqrt
+from numpy import median
 
 #from shapely.geometry import Polygon
 
@@ -582,9 +583,10 @@
     with a trajectory and a geometry (constant volume over time) and a usertype (e.g. road user) coded as a number (see 
     '''
 
-    def __init__(self, num = None, timeInterval = None, positions = None, geometry = None, userType = None):
+    def __init__(self, num = None, timeInterval = None, positions = None, velocities = None, geometry = None, userType = None):
         super(MovingObject, self).__init__(num, timeInterval)
         self.positions = positions
+        self.velocities = velocities
         self.geometry = geometry
         self.userType = userType
         self.features = None
@@ -670,6 +672,15 @@
         at constant speed'''
         return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration)
 
+    def classifyUserTypeSpeed(self, threshold, statisticsFunc = median):
+        '''Classifies slow and fast road users
+        slow: non-motorized -> pedestrians
+        fast: motorized -> cars'''
+        if statisticsFunc(self.velocities.norm()) >= threshold:
+            self.setUserType(userType2Num['car'])
+        else:
+            self.setUserType(userType2Num['pedestrian'])
+
     @staticmethod
     def collisionCourseDotProduct(movingObject1, movingObject2, instant):
         'A positive result indicates that the road users are getting closer'