Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 616:0791b3b55b8f
Merge
author | MohamedGomaa |
---|---|
date | Wed, 10 Dec 2014 14:18:30 -0500 |
parents | 0954aaf28231 078adacd72a4 |
children | dc2d0a0d7fe1 |
comparison
equal
deleted
inserted
replaced
615:0954aaf28231 | 616:0791b3b55b8f |
---|---|
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''' |
1155 relativePositions[(j,i)] = -relativePositions[(i,j)] | 1155 relativePositions[(j,i)] = -relativePositions[(i,j)] |
1156 | 1156 |
1157 ### | 1157 ### |
1158 # User Type Classification | 1158 # User Type Classification |
1159 ### | 1159 ### |
1160 def classifyUserTypeSpeedMotorized(self, threshold, percentileFactor=95, ignoreNInstantsAtEnds = 0): | 1160 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, ignoreNInstantsAtEnds = 0): |
1161 '''Classifies slow and fast road users | 1161 '''Classifies slow and fast road users |
1162 slow: non-motorized -> pedestrians | 1162 slow: non-motorized -> pedestrians |
1163 fast: motorized -> cars | 1163 fast: motorized -> cars |
1164 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.''' | 1164 |
1165 aggregationFunc can be any function that can be applied to a vector of speeds, including percentile: | |
1166 aggregationFunc = lambda x: percentile(x, percentileFactor) # where percentileFactor is 85 for 85th percentile''' | |
1165 if ignoreNInstantsAtEnds > 0: | 1167 if ignoreNInstantsAtEnds > 0: |
1166 speeds = self.getSpeeds()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds] | 1168 speeds = self.getSpeeds()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds] |
1167 else: | 1169 else: |
1168 speeds = self.getSpeeds() | 1170 speeds = self.getSpeeds() |
1169 if percentile(speeds,percentileFactor) >= threshold: | 1171 if aggregationFunc(speeds) >= threshold: |
1170 self.setUserType(userType2Num['car']) | 1172 self.setUserType(userType2Num['car']) |
1171 else: | 1173 else: |
1172 self.setUserType(userType2Num['pedestrian']) | 1174 self.setUserType(userType2Num['pedestrian']) |
1173 | 1175 |
1174 def classifyUserTypeSpeed(self, speedProbabilities, aggregationFunc = median): | 1176 def classifyUserTypeSpeed(self, speedProbabilities, aggregationFunc = median): |