comparison python/moving.py @ 608:078adacd72a4

moving.py integrating Mohamed's comments refactored
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 26 Nov 2014 19:49:13 +0000
parents 84690dfe5560
children 0791b3b55b8f
comparison
equal deleted inserted replaced
607:84690dfe5560 608:078adacd72a4
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,percentile 8 from numpy import median
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.computeCumulativeDistances()/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1))) 793 return self.getCumulativeDistance(self.length()-1)/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, percentileFactor=95, ignoreNInstantsAtEnds = 0): 1159 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, 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
1164 aggregationFunc can be any function that can be applied to a vector of speeds, including percentile:
1165 aggregationFunc = lambda x: percentile(x, percentileFactor) # where percentileFactor is 85 for 85th percentile'''
1164 if ignoreNInstantsAtEnds > 0: 1166 if ignoreNInstantsAtEnds > 0:
1165 speeds = self.getSpeeds()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds] 1167 speeds = self.getSpeeds()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds]
1166 else: 1168 else:
1167 speeds = self.getSpeeds() 1169 speeds = self.getSpeeds()
1168 if percentile(speeds,percentileFactor) >= threshold: 1170 if aggregationFunc(speeds) >= threshold:
1169 self.setUserType(userType2Num['car']) 1171 self.setUserType(userType2Num['car'])
1170 else: 1172 else:
1171 self.setUserType(userType2Num['pedestrian']) 1173 self.setUserType(userType2Num['pedestrian'])
1172 1174
1173 def classifyUserTypeSpeed(self, speedProbabilities, aggregationFunc = median): 1175 def classifyUserTypeSpeed(self, speedProbabilities, aggregationFunc = median):