Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 863:a8ca72dc1564
work on user detectors
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 08 Nov 2016 17:59:40 -0500 |
parents | 07fb949ff98f |
children | eb2f8ce2b39d |
comparison
equal
deleted
inserted
replaced
862:2d6249fe905a | 863:a8ca72dc1564 |
---|---|
944 'Returns the positions very step' | 944 'Returns the positions very step' |
945 return Trajectory([self.positions[0][::step], | 945 return Trajectory([self.positions[0][::step], |
946 self.positions[1][::step]]) | 946 self.positions[1][::step]]) |
947 | 947 |
948 if shapelyAvailable: | 948 if shapelyAvailable: |
949 def getInstantsInPolygon(self, polygon): | |
950 '''Returns the list of instants at which the trajectory is in the polygon''' | |
951 instants = [] | |
952 n = self.length() | |
953 for t, x, y in zip(range(n), self.positions[0], self.positions[1]): | |
954 if polygon.contains(shapelyPoint(x, y)): | |
955 instants.append(t) | |
956 return instants | |
957 | |
949 def getTrajectoryInPolygon(self, polygon, t2 = None): | 958 def getTrajectoryInPolygon(self, polygon, t2 = None): |
950 '''Returns the trajectory built with the set of points inside the (shapely) polygon | 959 '''Returns the trajectory built with the set of points inside the (shapely) polygon |
951 The polygon could be a prepared polygon (faster) from prepared.prep | 960 The polygon could be a prepared polygon (faster) from prepared.prep |
952 | 961 |
953 t2 is another trajectory (could be velocities) | 962 t2 is another trajectory (could be velocities) |
964 if inp: | 973 if inp: |
965 traj2.addPositionXY(x, y) | 974 traj2.addPositionXY(x, y) |
966 return traj, traj2 | 975 return traj, traj2 |
967 | 976 |
968 def proportionInPolygon(self, polygon, minProportion = 0.5): | 977 def proportionInPolygon(self, polygon, minProportion = 0.5): |
969 inPolygon = [polygon.contains(shapelyPoint(x, y)) for x, y in zip(self.positions[0], self.positions[1])] | 978 instants = self.getInstantsInPolygon(polygon) |
970 lengthThreshold = float(self.length())*minProportion | 979 lengthThreshold = float(self.length())*minProportion |
971 return sum(inPolygon) >= lengthThreshold | 980 return len(instants) >= lengthThreshold |
972 else: | 981 else: |
973 def getTrajectoryInPolygon(self, polygon, t2 = None): | 982 def getTrajectoryInPolygon(self, polygon, t2 = None): |
974 '''Returns the trajectory built with the set of points inside the polygon | 983 '''Returns the trajectory built with the set of points inside the polygon |
975 (array of Nx2 coordinates of the polygon vertices)''' | 984 (array of Nx2 coordinates of the polygon vertices)''' |
976 traj = Trajectory() | 985 traj = Trajectory() |