Mercurial Hosting > traffic-intelligence
diff python/moving.py @ 546:6c0923f1ce68
add some functions for behaviour analysis
author | MohamedGomaa |
---|---|
date | Thu, 03 Jul 2014 14:30:20 -0400 |
parents | f012a8ad7a0e |
children | b5525249eda1 |
line wrap: on
line diff
--- a/python/moving.py Thu Jul 03 13:57:32 2014 -0400 +++ b/python/moving.py Thu Jul 03 14:30:20 2014 -0400 @@ -450,6 +450,7 @@ def __repr__(self): return self.__str__() + def __iter__(self): self.iterInstantNum = 0 return self @@ -803,6 +804,17 @@ return MovingObject.distances(obj1, obj2, instant).min() @staticmethod + def distances2(obj1, obj2, instant1,instant2): + from scipy.spatial.distance import cdist + positions1 = [f.getPositionAtInstant(instant1).astuple() for f in obj1.features if f.existsAtInstant(instant1)] + positions2 = [f.getPositionAtInstant(instant2).astuple() for f in obj2.features if f.existsAtInstant(instant2)] + return cdist(positions1, positions2, metric = 'euclidean') + + @staticmethod + def minDistance2(obj1, obj2, instant1,instant2): + return MovingObject.distances2(obj1, obj2, instant1,instant2).min() + + @staticmethod def maxDistance(obj1, obj2, instant): return MovingObject.distances(obj1, obj2, instant).max() @@ -821,7 +833,11 @@ else: print('Load features to compute a maximum size') return None - + + def setRoutes(self,startCode,endCode): + self.startRouteID=startCode + self.endRouteID=endCode + def getInstantsCrossingLane(self, p1, p2): '''Returns the instant(s) at which the object passes from one side of the segment to the other @@ -942,6 +958,7 @@ # what to do: threshold for most common type? self.setUserType() return possibleUserTypes + @staticmethod def collisionCourseDotProduct(movingObject1, movingObject2, instant): 'A positive result indicates that the road users are getting closer'