diff python/moving.py @ 607:84690dfe5560

add some functions for behaviour analysis
author MohamedGomaa
date Tue, 25 Nov 2014 22:49:47 -0500
parents 6ebfb43e938e
children 078adacd72a4 0954aaf28231
line wrap: on
line diff
--- a/python/moving.py	Mon Nov 24 13:02:10 2014 -0500
+++ b/python/moving.py	Tue Nov 25 22:49:47 2014 -0500
@@ -5,7 +5,7 @@
 import cvutils
 
 from math import sqrt
-from numpy import median
+from numpy import median,percentile
 
 try:
     from shapely.geometry import Polygon, Point as shapelyPoint
@@ -790,7 +790,7 @@
         return False
 
     def wiggliness(self):
-        return self.cumulatedDisplacement()/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1)))
+        return self.computeCumulativeDistances()/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1)))
 
     def getIntersections(self, p1, p2):
         '''Returns a list of the indices at which the trajectory 
@@ -1156,15 +1156,16 @@
     ###
     # User Type Classification
     ###
-    def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, ignoreNInstantsAtEnds = 0):
+    def classifyUserTypeSpeedMotorized(self, threshold, percentileFactor=95, ignoreNInstantsAtEnds = 0):
         '''Classifies slow and fast road users
         slow: non-motorized -> pedestrians
-        fast: motorized -> cars'''
+        fast: motorized -> cars
+        The percentile function is the same as the median if percentileFactor=50, the same as the minimum if percentileFactor=0 and the same as the maximum if percentileFactor=100.'''
         if ignoreNInstantsAtEnds > 0:
             speeds = self.getSpeeds()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds]
         else:
             speeds = self.getSpeeds()
-        if aggregationFunc(speeds) >= threshold:
+        if percentile(speeds,percentileFactor) >= threshold:
             self.setUserType(userType2Num['car'])
         else:
             self.setUserType(userType2Num['pedestrian'])