Mercurial Hosting > traffic-intelligence
diff python/events.py @ 887:e2452abba0e7
added option to compute PET in safety analysis script, and save in database
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 22 Mar 2017 10:44:24 -0400 |
parents | 4749b71aa7fb |
children | b67a784beb69 |
line wrap: on
line diff
--- a/python/events.py Tue Mar 21 17:51:38 2017 -0400 +++ b/python/events.py Wed Mar 22 10:44:24 2017 -0400 @@ -165,9 +165,15 @@ self.roadUser1.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) self.roadUser2.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) - def play(self, videoFilename, homography = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1.): + def play(self, videoFilename, homography = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1., allUserInstants = False): if self.roadUser1 is not None and self.roadUser2 is not None: - cvutils.displayTrajectories(videoFilename, [self.roadUser1, self.roadUser2], homography = homography, firstFrameNum = self.getFirstInstant(), lastFrameNumArg = self.getLastInstant(), undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) + if allUserInstants: + firstFrameNum = min(self.roadUser1.getFirstInstant(), self.roadUser2.getFirstInstant()) + lastFrameNum = max(self.roadUser1.getLastInstant(), self.roadUser2.getLastInstant()) + else: + firstFrameNum = self.getFirstInstant() + lastFrameNum = self.getLastInstant() + cvutils.displayTrajectories(videoFilename, [self.roadUser1, self.roadUser2], homography = homography, firstFrameNum = firstFrameNum, lastFrameNumArg = lastFrameNum, undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) else: print('Please set the interaction road user attributes roadUser1 and roadUser1 through the method setRoadUsers') @@ -237,10 +243,9 @@ # TODO add probability of collision, and probability of successful evasive action def computePET(self, collisionDistanceThreshold): - # TODO add crossing zone - pet = moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold) - if pet is not None: # TODO get crossing zone and time - self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[10], {0: pet}, mostSevereIsMax = False)) + pet, t1, t2= moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold) + if pet is not None: + self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[10], {min(t1, t2): pet}, mostSevereIsMax = False)) def setCollision(self, collision): '''indicates if it is a collision: argument should be boolean'''