comparison trafficintelligence/moving.py @ 1203:7b3384a8e409

second version of code loading kitti data, to clean
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 22 Mar 2023 15:40:33 -0400
parents 0475b4cd0cfb
children 3905b393ade0
comparison
equal deleted inserted replaced
1202:059b7282aa09 1203:7b3384a8e409
355 @staticmethod 355 @staticmethod
356 def distanceNorm2(p1, p2): 356 def distanceNorm2(p1, p2):
357 return (p1-p2).norm2() 357 return (p1-p2).norm2()
358 358
359 @staticmethod 359 @staticmethod
360 def plotAll(points, options = '', **kwargs): 360 def plotAll(points, options = '', closePolygon = False, **kwargs):
361 plot([p.x for p in points], [p.y for p in points], options, **kwargs) 361 xCoords = [p.x for p in points]
362 yCoords = [p.y for p in points]
363 if closePolygon:
364 xCoords.append[0]
365 yCoords.append[0]
366 plot(xCoords, yCoords, options, **kwargs)
362 367
363 def similarOrientation(self, refDirection, cosineThreshold): 368 def similarOrientation(self, refDirection, cosineThreshold):
364 'Indicates whether the cosine of the vector and refDirection is smaller than cosineThreshold' 369 'Indicates whether the cosine of the vector and refDirection is smaller than cosineThreshold'
365 return Point.cosine(self, refDirection) >= cosineThreshold 370 return Point.cosine(self, refDirection) >= cosineThreshold
366 371
1251 '''Class for moving objects: a spatio-temporal object 1256 '''Class for moving objects: a spatio-temporal object
1252 with a trajectory and a geometry (constant volume over time) 1257 with a trajectory and a geometry (constant volume over time)
1253 and a usertype (e.g. road user) coded as a number (see userTypeNames) 1258 and a usertype (e.g. road user) coded as a number (see userTypeNames)
1254 ''' 1259 '''
1255 1260
1256 def __init__(self, num = None, timeInterval = None, positions = None, velocities = None, geometry = None, userType = userType2Num['unknown'], nObjects = None, initCurvilinear = False): 1261 def __init__(self, num = None, timeInterval = None, positions = None, velocities = None, geometry = None, userType = userType2Num['unknown'], nObjects = None, features = None, initCurvilinear = False):
1257 super(MovingObject, self).__init__(num, timeInterval) 1262 super(MovingObject, self).__init__(num, timeInterval)
1258 if initCurvilinear: 1263 if initCurvilinear:
1259 self.curvilinearPositions = positions 1264 self.curvilinearPositions = positions
1260 self.curvilinearVelocities = velocities # third component is (previousAlignmentIdx, newAlignmentIdx) or None if no change 1265 self.curvilinearVelocities = velocities # third component is (previousAlignmentIdx, newAlignmentIdx) or None if no change
1261 else: 1266 else:
1262 self.positions = positions 1267 self.positions = positions
1263 self.velocities = velocities 1268 self.velocities = velocities
1264 self.geometry = geometry 1269 self.geometry = geometry
1265 self.userType = userType 1270 self.userType = userType
1266 self.setNObjects(nObjects) # a feature has None for nObjects 1271 self.setNObjects(nObjects) # a feature has None for nObjects
1267 self.features = None 1272 self.features = features
1268 # compute bounding polygon from trajectory 1273 # compute bounding polygon from trajectory
1269 1274
1270 @staticmethod 1275 @staticmethod
1271 def croppedTimeInterval(obj, value, after = True): 1276 def croppedTimeInterval(obj, value, after = True):
1272 newTimeInterval = TimeInterval(obj.getFirstInstant(), min(value, obj.getLastInstant())) if after else TimeInterval(max(obj.getFirstInstant(), value), obj.getLastInstant()) 1277 newTimeInterval = TimeInterval(obj.getFirstInstant(), min(value, obj.getLastInstant())) if after else TimeInterval(max(obj.getFirstInstant(), value), obj.getLastInstant())
1649 if withIds: 1654 if withIds:
1650 self.positions.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, self.getNum(), **kwargs) 1655 self.positions.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, self.getNum(), **kwargs)
1651 else: 1656 else:
1652 self.positions.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, None, **kwargs) 1657 self.positions.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, None, **kwargs)
1653 1658
1659 def plotOutlineAtInstant(self, t, options = '', **kwargs):
1660 if self.hasFeatures():
1661 points = [f.getPositionAtInstant(t) for f in self.getFeatures()]
1662 Point.plotAll(points, options, True, kwargs)
1663
1654 def play(self, videoFilename, homography = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1.): 1664 def play(self, videoFilename, homography = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1.):
1655 cvutils.displayTrajectories(videoFilename, [self], homography = homography, firstFrameNum = self.getFirstInstant(), lastFrameNumArg = self.getLastInstant(), undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) 1665 cvutils.displayTrajectories(videoFilename, [self], homography = homography, firstFrameNum = self.getFirstInstant(), lastFrameNumArg = self.getLastInstant(), undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication)
1656 1666
1657 def speedDiagnostics(self, framerate = 1., display = False, nInstantsIgnoredAtEnds=0): 1667 def speedDiagnostics(self, framerate = 1., display = False, nInstantsIgnoredAtEnds=0):
1658 speeds = framerate*self.getSpeeds(nInstantsIgnoredAtEnds) 1668 speeds = framerate*self.getSpeeds(nInstantsIgnoredAtEnds)