Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 270:05c9b0cb8202
updates for drawing
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 02 Aug 2012 05:35:57 -0400 |
| parents | 0c0b92f621f6 |
| children | 8d44fb1756bc |
comparison
equal
deleted
inserted
replaced
| 269:a9988971aac8 | 270:05c9b0cb8202 |
|---|---|
| 374 | 374 |
| 375 def addPosition(self, p): | 375 def addPosition(self, p): |
| 376 self.addPositionXY(p.x, p.y) | 376 self.addPositionXY(p.x, p.y) |
| 377 | 377 |
| 378 @staticmethod | 378 @staticmethod |
| 379 def _draw(positions, options = '', withOrigin = False, lastCoordinate = None, **kwargs): | 379 def _draw(positions, options = '', withOrigin = False, lastCoordinate = None, timeStep = 1, **kwargs): |
| 380 from matplotlib.pylab import plot | 380 from matplotlib.pylab import plot |
| 381 if lastCoordinate == None: | 381 if lastCoordinate == None: |
| 382 plot(positions[0], positions[1], options, **kwargs) | 382 plot(positions[0][::timeStep], positions[1][::timeStep], options, **kwargs) |
| 383 elif 0 <= lastCoordinate <= len(positions[0]): | 383 elif 0 <= lastCoordinate <= len(positions[0]): |
| 384 plot(positions[0][:lastCoordinate], positions[1][:lastCoordinate], options, **kwargs) | 384 plot(positions[0][:lastCoordinate:timeStep], positions[1][:lastCoordinate:timeStep], options, **kwargs) |
| 385 if withOrigin: | 385 if withOrigin: |
| 386 plot([positions[0][0]], [positions[1][0]], 'ro', **kwargs) | 386 plot([positions[0][0]], [positions[1][0]], 'ro', **kwargs) |
| 387 | 387 |
| 388 def project(self, homography): | 388 def project(self, homography): |
| 389 from numpy.core.multiarray import array | 389 from numpy.core.multiarray import array |
| 390 projected = cvutils.projectArray(homography, array(self.positions)) | 390 projected = cvutils.projectArray(homography, array(self.positions)) |
| 391 return Trajectory(projected) | 391 return Trajectory(projected) |
| 392 | 392 |
| 393 def draw(self, options = '', withOrigin = False, **kwargs): | 393 def draw(self, options = '', withOrigin = False, timeStep = 1, **kwargs): |
| 394 Trajectory._draw(self.positions, options, withOrigin,**kwargs) | 394 Trajectory._draw(self.positions, options, withOrigin, None, timeStep, **kwargs) |
| 395 | 395 |
| 396 def drawAt(self, lastCoordinate, options = '', withOrigin = False, **kwargs): | 396 def drawAt(self, lastCoordinate, options = '', withOrigin = False, timeStep = 1, **kwargs): |
| 397 Trajectory._draw(self.positions, options, withOrigin, lastCoordinate, **kwargs) | 397 Trajectory._draw(self.positions, options, withOrigin, lastCoordinate, timeStep, **kwargs) |
| 398 | 398 |
| 399 def drawOnWorldImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False, **kwargs): | 399 def drawOnWorldImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False, timeStep = 1, **kwargs): |
| 400 from matplotlib.pylab import plot | 400 from matplotlib.pylab import plot |
| 401 imgPositions = [[x*nPixelsPerUnitDistance for x in self.positions[0]], | 401 imgPositions = [[x*nPixelsPerUnitDistance for x in self.positions[0]], |
| 402 [-x*nPixelsPerUnitDistance+imageHeight for x in self.positions[1]]] | 402 [-x*nPixelsPerUnitDistance+imageHeight for x in self.positions[1]]] |
| 403 Trajectory._draw(imgPositions, options, withOrigin, **kwargs) | 403 Trajectory._draw(imgPositions, options, withOrigin, timeStep, **kwargs) |
| 404 | 404 |
| 405 def getXCoordinates(self): | 405 def getXCoordinates(self): |
| 406 return self.positions[0] | 406 return self.positions[0] |
| 407 | 407 |
| 408 def getYCoordinates(self): | 408 def getYCoordinates(self): |
| 566 return self.positions.getXCoordinates() | 566 return self.positions.getXCoordinates() |
| 567 | 567 |
| 568 def getYCoordinates(self): | 568 def getYCoordinates(self): |
| 569 return self.positions.getYCoordinates() | 569 return self.positions.getYCoordinates() |
| 570 | 570 |
| 571 def draw(self, options = '', withOrigin = False, **kwargs): | 571 def draw(self, options = '', withOrigin = False, timeStep = 1, **kwargs): |
| 572 self.positions.draw(options, withOrigin, **kwargs) | 572 self.positions.draw(options, withOrigin, timeStep, **kwargs) |
| 573 | 573 |
| 574 def drawOnWorldImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False, **kwargs): | 574 def drawOnWorldImage(self, nPixelsPerUnitDistance, imageHeight, options = '', withOrigin = False, timeStep = 1, **kwargs): |
| 575 self.positions.drawOnWorldImage(nPixelsPerUnitDistance, imageHeight, options, withOrigin, **kwargs) | 575 self.positions.drawOnWorldImage(nPixelsPerUnitDistance, imageHeight, options, withOrigin, timeStep, **kwargs) |
| 576 | 576 |
| 577 def play(self, videoFilename, homography = None): | 577 def play(self, videoFilename, homography = None): |
| 578 cvutils.displayTrajectories(videoFilename, [self], homography, self.getFirstInstant(), self.getLastInstant()) | 578 cvutils.displayTrajectories(videoFilename, [self], homography, self.getFirstInstant(), self.getLastInstant()) |
| 579 | 579 |
| 580 def getInstantsCrossingLane(self, p1, p2): | 580 def getInstantsCrossingLane(self, p1, p2): |
