Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 936:56cc8a1f7082
removed all old versions of projection methods
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Fri, 14 Jul 2017 16:48:42 -0400 |
| parents | 0e63a918a1ca |
| children | b67a784beb69 |
comparison
equal
deleted
inserted
replaced
| 935:0e63a918a1ca | 936:56cc8a1f7082 |
|---|---|
| 261 | 261 |
| 262 if shapelyAvailable: | 262 if shapelyAvailable: |
| 263 def asShapely(self): | 263 def asShapely(self): |
| 264 return shapelyPoint(self.x, self.y) | 264 return shapelyPoint(self.x, self.y) |
| 265 | 265 |
| 266 def project(self, homography): | 266 def homographyProject(self, homography): |
| 267 projected = cvutils.projectArray(homography, array([[self.x], [self.y]])) | 267 projected = cvutils.homographyProject(array([[self.x], [self.y]]), homography) |
| 268 return Point(projected[0], projected[1]) | 268 return Point(projected[0], projected[1]) |
| 269 | 269 |
| 270 def inPolygon(self, polygon): | 270 def inPolygon(self, polygon): |
| 271 '''Indicates if the point x, y is inside the polygon | 271 '''Indicates if the point x, y is inside the polygon |
| 272 (array of Nx2 coordinates of the polygon vertices) | 272 (array of Nx2 coordinates of the polygon vertices) |
| 1171 | 1171 |
| 1172 def getObjectsInMask(self, mask, homography = None, minLength = 1): | 1172 def getObjectsInMask(self, mask, homography = None, minLength = 1): |
| 1173 '''Returns new objects made of the positions in the mask | 1173 '''Returns new objects made of the positions in the mask |
| 1174 mask is in the destination of the homography space''' | 1174 mask is in the destination of the homography space''' |
| 1175 if homography is not None: | 1175 if homography is not None: |
| 1176 self.projectedPositions = self.positions.project(homography) | 1176 self.projectedPositions = self.positions.homographyProject(homography) |
| 1177 else: | 1177 else: |
| 1178 self.projectedPositions = self.positions | 1178 self.projectedPositions = self.positions |
| 1179 def inMask(positions, i, mask): | 1179 def inMask(positions, i, mask): |
| 1180 p = positions[i] | 1180 p = positions[i] |
| 1181 return mask[p.y, p.x] != 0. | 1181 return mask[p.y, p.x] != 0. |
| 1642 TODO: areas could be a wrapper object with a contains method that would work for polygons and images (with wrapper class) | 1642 TODO: areas could be a wrapper object with a contains method that would work for polygons and images (with wrapper class) |
| 1643 skip frames at beginning/end?''' | 1643 skip frames at beginning/end?''' |
| 1644 print('not implemented/tested yet') | 1644 print('not implemented/tested yet') |
| 1645 if not hasattr(self, projectedPositions): | 1645 if not hasattr(self, projectedPositions): |
| 1646 if homography is not None: | 1646 if homography is not None: |
| 1647 self.projectedPositions = obj.positions.project(homography) | 1647 self.projectedPositions = obj.positions.homographyProject(homography) |
| 1648 else: | 1648 else: |
| 1649 self.projectedPositions = obj.positions | 1649 self.projectedPositions = obj.positions |
| 1650 possibleUserTypes = {userType: 0 for userType in range(len(userTypenames))} | 1650 possibleUserTypes = {userType: 0 for userType in range(len(userTypenames))} |
| 1651 for p in self.projectedPositions: | 1651 for p in self.projectedPositions: |
| 1652 for userTypename in areas: | 1652 for userTypename in areas: |
| 1714 self.bottomRightPositions = bottomRightPositions.getPositions() | 1714 self.bottomRightPositions = bottomRightPositions.getPositions() |
| 1715 | 1715 |
| 1716 def computeCentroidTrajectory(self, homography = None): | 1716 def computeCentroidTrajectory(self, homography = None): |
| 1717 self.positions = self.topLeftPositions.add(self.bottomRightPositions).multiply(0.5) | 1717 self.positions = self.topLeftPositions.add(self.bottomRightPositions).multiply(0.5) |
| 1718 if homography is not None: | 1718 if homography is not None: |
| 1719 self.positions = self.positions.project(homography) | 1719 self.positions = self.positions.homographyProject(homography) |
| 1720 | 1720 |
| 1721 def matches(self, obj, instant, matchingDistance): | 1721 def matches(self, obj, instant, matchingDistance): |
| 1722 '''Indicates if the annotation matches obj (MovingObject) | 1722 '''Indicates if the annotation matches obj (MovingObject) |
| 1723 with threshold matchingDistance | 1723 with threshold matchingDistance |
| 1724 Returns distance if below matchingDistance, matchingDistance+1 otherwise | 1724 Returns distance if below matchingDistance, matchingDistance+1 otherwise |
