Mercurial Hosting > traffic-intelligence
diff python/moving.py @ 549:b5525249eda1
Merged in mohamedgomaa/trafficintelligence (pull request #7)
add some functions for behaviour analysis and corrected a few bugs
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 08 Jul 2014 16:32:09 -0400 |
parents | cb213269d330 6c0923f1ce68 |
children | 5668af2ff515 |
line wrap: on
line diff
--- a/python/moving.py Tue Jul 08 15:51:43 2014 -0400 +++ b/python/moving.py Tue Jul 08 16:32:09 2014 -0400 @@ -450,6 +450,7 @@ def __repr__(self): return self.__str__() + def __iter__(self): self.iterInstantNum = 0 return self @@ -822,6 +823,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() @@ -840,7 +852,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 @@ -961,6 +977,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'