Mercurial Hosting > traffic-intelligence
changeset 627:82e9f78a4714
added test for location for trajectories
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 16 Feb 2015 08:41:14 +0100 |
parents | 35155ac2a294 |
children | 977407c9f815 |
files | python/events.py python/moving.py |
diffstat | 2 files changed, 23 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/python/events.py Sat Feb 14 19:18:14 2015 -0500 +++ b/python/events.py Mon Feb 16 08:41:14 2015 +0100 @@ -153,7 +153,7 @@ minDistance[instant] = moving.MovingObject.minDistance(self.roadUser1, self.roadUser2, instant) self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[3], minDistance)) - def computeCrossingsCollisions(self, predictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None, nProcesses = 1,usePrototypes=True,route1= (-1,-1),route2=(-1,-1),prototypes={},secondStepPrototypes={},nMatching={},objects=[],noiseEntryNums=[],noiseExitNums=[],minSimilarity=0.1,mostMatched=None,useDestination=True,useSpeedPrototype=True,acceptPartialLength=30, step=1): + def computeCrossingsCollisions(self, predictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None, nProcesses = 1, usePrototypes=False, route1= (-1,-1), route2=(-1,-1), prototypes={}, secondStepPrototypes={}, nMatching={}, objects=[], noiseEntryNums=[], noiseExitNums=[], minSimilarity=0.1, mostMatched=None, useDestination=True, useSpeedPrototype=True, acceptPartialLength=30, step=1): '''Computes all crossing and collision points at each common instant for two road users. ''' self.collisionPoints={} self.crossingZones={}
--- a/python/moving.py Sat Feb 14 19:18:14 2015 -0500 +++ b/python/moving.py Mon Feb 16 08:41:14 2015 +0100 @@ -235,7 +235,7 @@ projected = cvutils.projectArray(homography, array([[self.x], [self.y]])) return Point(projected[0], projected[1]) - def inPolygonNoShapely(self, polygon): + def inPolygon(self, polygon): '''Indicates if the point x, y is inside the polygon (array of Nx2 coordinates of the polygon vertices) @@ -793,10 +793,7 @@ for p in self: if p.similarOrientation(refDirection, cosineThreshold): count += 1 - if count > lengthThreshold: - return True - else: - return False + return count >= lengthThreshold def wiggliness(self): return self.getCumulativeDistance(self.length()-1)/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1))) @@ -829,15 +826,6 @@ else: return None - def getTrajectoryInPolygonNoShapely(self, polygon): - '''Returns the trajectory built with the set of points inside the polygon - (array of Nx2 coordinates of the polygon vertices)''' - traj = Trajectory() - for p in self: - if p.inPolygonNoShapely(polygon): - traj.addPosition(p) - return traj - if shapelyAvailable: def getTrajectoryInPolygon(self, polygon): '''Returns the trajectory built with the set of points inside the (shapely) polygon''' @@ -846,7 +834,26 @@ for p in pointsInPolygon(points, polygon): traj.addPositionXY(p.x, p.y) return traj - + + def proportionInPolygon(self, polygon, minProportion = 0.5): + pointsIn = pointsInPolygon([p.asShapely() for p in self], polygon) + lengthThreshold = float(self.length())*minProportion + return len(pointsIn) >= lengthThreshold + else: + def getTrajectoryInPolygon(self, polygon): + '''Returns the trajectory built with the set of points inside the polygon + (array of Nx2 coordinates of the polygon vertices)''' + traj = Trajectory() + for p in self: + if p.inPolygon(polygon): + traj.addPosition(p) + return traj + + def proportionInPolygon(self, polygon, minProportion = 0.5): + pointsInPolygon = [p.inPolygon(polygon) for p in self] + lengthThreshold = float(self.length())*minProportion + return len(pointsInPolygon) >= lengthThreshold + @staticmethod def lcss(t1, t2, lcss): return lcss.compute(t1, t2)