Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 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 | 69a98f84f3eb |
comparison
equal
deleted
inserted
replaced
626:35155ac2a294 | 627:82e9f78a4714 |
---|---|
233 def project(self, homography): | 233 def project(self, homography): |
234 from numpy.core.multiarray import array | 234 from numpy.core.multiarray import array |
235 projected = cvutils.projectArray(homography, array([[self.x], [self.y]])) | 235 projected = cvutils.projectArray(homography, array([[self.x], [self.y]])) |
236 return Point(projected[0], projected[1]) | 236 return Point(projected[0], projected[1]) |
237 | 237 |
238 def inPolygonNoShapely(self, polygon): | 238 def inPolygon(self, polygon): |
239 '''Indicates if the point x, y is inside the polygon | 239 '''Indicates if the point x, y is inside the polygon |
240 (array of Nx2 coordinates of the polygon vertices) | 240 (array of Nx2 coordinates of the polygon vertices) |
241 | 241 |
242 taken from http://www.ariel.com.au/a/python-point-int-poly.html | 242 taken from http://www.ariel.com.au/a/python-point-int-poly.html |
243 | 243 |
791 count = 0 | 791 count = 0 |
792 lengthThreshold = float(self.length())*minProportion | 792 lengthThreshold = float(self.length())*minProportion |
793 for p in self: | 793 for p in self: |
794 if p.similarOrientation(refDirection, cosineThreshold): | 794 if p.similarOrientation(refDirection, cosineThreshold): |
795 count += 1 | 795 count += 1 |
796 if count > lengthThreshold: | 796 return count >= lengthThreshold |
797 return True | |
798 else: | |
799 return False | |
800 | 797 |
801 def wiggliness(self): | 798 def wiggliness(self): |
802 return self.getCumulativeDistance(self.length()-1)/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1))) | 799 return self.getCumulativeDistance(self.length()-1)/float(Point.distanceNorm2(self.__getitem__(0),self.__getitem__(self.length()-1))) |
803 | 800 |
804 def getIntersections(self, p1, p2): | 801 def getIntersections(self, p1, p2): |
827 return Trajectory([self.positions[0][inter.first:inter.last+1], | 824 return Trajectory([self.positions[0][inter.first:inter.last+1], |
828 self.positions[1][inter.first:inter.last+1]]) | 825 self.positions[1][inter.first:inter.last+1]]) |
829 else: | 826 else: |
830 return None | 827 return None |
831 | 828 |
832 def getTrajectoryInPolygonNoShapely(self, polygon): | |
833 '''Returns the trajectory built with the set of points inside the polygon | |
834 (array of Nx2 coordinates of the polygon vertices)''' | |
835 traj = Trajectory() | |
836 for p in self: | |
837 if p.inPolygonNoShapely(polygon): | |
838 traj.addPosition(p) | |
839 return traj | |
840 | |
841 if shapelyAvailable: | 829 if shapelyAvailable: |
842 def getTrajectoryInPolygon(self, polygon): | 830 def getTrajectoryInPolygon(self, polygon): |
843 '''Returns the trajectory built with the set of points inside the (shapely) polygon''' | 831 '''Returns the trajectory built with the set of points inside the (shapely) polygon''' |
844 traj = Trajectory() | 832 traj = Trajectory() |
845 points = [p.asShapely() for p in self] | 833 points = [p.asShapely() for p in self] |
846 for p in pointsInPolygon(points, polygon): | 834 for p in pointsInPolygon(points, polygon): |
847 traj.addPositionXY(p.x, p.y) | 835 traj.addPositionXY(p.x, p.y) |
848 return traj | 836 return traj |
849 | 837 |
838 def proportionInPolygon(self, polygon, minProportion = 0.5): | |
839 pointsIn = pointsInPolygon([p.asShapely() for p in self], polygon) | |
840 lengthThreshold = float(self.length())*minProportion | |
841 return len(pointsIn) >= lengthThreshold | |
842 else: | |
843 def getTrajectoryInPolygon(self, polygon): | |
844 '''Returns the trajectory built with the set of points inside the polygon | |
845 (array of Nx2 coordinates of the polygon vertices)''' | |
846 traj = Trajectory() | |
847 for p in self: | |
848 if p.inPolygon(polygon): | |
849 traj.addPosition(p) | |
850 return traj | |
851 | |
852 def proportionInPolygon(self, polygon, minProportion = 0.5): | |
853 pointsInPolygon = [p.inPolygon(polygon) for p in self] | |
854 lengthThreshold = float(self.length())*minProportion | |
855 return len(pointsInPolygon) >= lengthThreshold | |
856 | |
850 @staticmethod | 857 @staticmethod |
851 def lcss(t1, t2, lcss): | 858 def lcss(t1, t2, lcss): |
852 return lcss.compute(t1, t2) | 859 return lcss.compute(t1, t2) |
853 | 860 |
854 class CurvilinearTrajectory(Trajectory): | 861 class CurvilinearTrajectory(Trajectory): |