comparison 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
comparison
equal deleted inserted replaced
606:75ad9c0d6cc3 607:84690dfe5560
3 3
4 import utils 4 import utils
5 import cvutils 5 import cvutils
6 6
7 from math import sqrt 7 from math import sqrt
8 from numpy import median 8 from numpy import median,percentile
9 9
10 try: 10 try:
11 from shapely.geometry import Polygon, Point as shapelyPoint 11 from shapely.geometry import Polygon, Point as shapelyPoint
12 from shapely.prepared import prep 12 from shapely.prepared import prep
13 shapelyAvailable = True 13 shapelyAvailable = True
788 if count > lengthThreshold: 788 if count > lengthThreshold:
789 return True 789 return True
790 return False 790 return False
791 791
792 def wiggliness(self): 792 def wiggliness(self):
793 return self.cumulatedDisplacement()/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1))) 793 return self.computeCumulativeDistances()/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1)))
794 794
795 def getIntersections(self, p1, p2): 795 def getIntersections(self, p1, p2):
796 '''Returns a list of the indices at which the trajectory 796 '''Returns a list of the indices at which the trajectory
797 intersects with the segment of extremities p1 and p2 797 intersects with the segment of extremities p1 and p2
798 the list is empty if there is no crossing''' 798 the list is empty if there is no crossing'''
1154 relativePositions[(j,i)] = -relativePositions[(i,j)] 1154 relativePositions[(j,i)] = -relativePositions[(i,j)]
1155 1155
1156 ### 1156 ###
1157 # User Type Classification 1157 # User Type Classification
1158 ### 1158 ###
1159 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, ignoreNInstantsAtEnds = 0): 1159 def classifyUserTypeSpeedMotorized(self, threshold, percentileFactor=95, ignoreNInstantsAtEnds = 0):
1160 '''Classifies slow and fast road users 1160 '''Classifies slow and fast road users
1161 slow: non-motorized -> pedestrians 1161 slow: non-motorized -> pedestrians
1162 fast: motorized -> cars''' 1162 fast: motorized -> cars
1163 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.'''
1163 if ignoreNInstantsAtEnds > 0: 1164 if ignoreNInstantsAtEnds > 0:
1164 speeds = self.getSpeeds()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds] 1165 speeds = self.getSpeeds()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds]
1165 else: 1166 else:
1166 speeds = self.getSpeeds() 1167 speeds = self.getSpeeds()
1167 if aggregationFunc(speeds) >= threshold: 1168 if percentile(speeds,percentileFactor) >= threshold:
1168 self.setUserType(userType2Num['car']) 1169 self.setUserType(userType2Num['car'])
1169 else: 1170 else:
1170 self.setUserType(userType2Num['pedestrian']) 1171 self.setUserType(userType2Num['pedestrian'])
1171 1172
1172 def classifyUserTypeSpeed(self, speedProbabilities, aggregationFunc = median): 1173 def classifyUserTypeSpeed(self, speedProbabilities, aggregationFunc = median):