comparison 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
comparison
equal deleted inserted replaced
886:d2eb8c93f7de 887:e2452abba0e7
163 163
164 def plotOnWorldImage(self, nPixelsPerUnitDistance, options = '', withOrigin = False, timeStep = 1, **kwargs): 164 def plotOnWorldImage(self, nPixelsPerUnitDistance, options = '', withOrigin = False, timeStep = 1, **kwargs):
165 self.roadUser1.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) 165 self.roadUser1.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs)
166 self.roadUser2.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) 166 self.roadUser2.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs)
167 167
168 def play(self, videoFilename, homography = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1.): 168 def play(self, videoFilename, homography = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1., allUserInstants = False):
169 if self.roadUser1 is not None and self.roadUser2 is not None: 169 if self.roadUser1 is not None and self.roadUser2 is not None:
170 cvutils.displayTrajectories(videoFilename, [self.roadUser1, self.roadUser2], homography = homography, firstFrameNum = self.getFirstInstant(), lastFrameNumArg = self.getLastInstant(), undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) 170 if allUserInstants:
171 firstFrameNum = min(self.roadUser1.getFirstInstant(), self.roadUser2.getFirstInstant())
172 lastFrameNum = max(self.roadUser1.getLastInstant(), self.roadUser2.getLastInstant())
173 else:
174 firstFrameNum = self.getFirstInstant()
175 lastFrameNum = self.getLastInstant()
176 cvutils.displayTrajectories(videoFilename, [self.roadUser1, self.roadUser2], homography = homography, firstFrameNum = firstFrameNum, lastFrameNumArg = lastFrameNum, undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication)
171 else: 177 else:
172 print('Please set the interaction road user attributes roadUser1 and roadUser1 through the method setRoadUsers') 178 print('Please set the interaction road user attributes roadUser1 and roadUser1 through the method setRoadUsers')
173 179
174 def computeIndicators(self): 180 def computeIndicators(self):
175 '''Computes the collision course cosine only if the cosine is positive''' 181 '''Computes the collision course cosine only if the cosine is positive'''
235 pPETs[i] = prediction.SafetyPoint.computeExpectedIndicator(cz) 241 pPETs[i] = prediction.SafetyPoint.computeExpectedIndicator(cz)
236 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[9], pPETs, mostSevereIsMax=False)) 242 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[9], pPETs, mostSevereIsMax=False))
237 # TODO add probability of collision, and probability of successful evasive action 243 # TODO add probability of collision, and probability of successful evasive action
238 244
239 def computePET(self, collisionDistanceThreshold): 245 def computePET(self, collisionDistanceThreshold):
240 # TODO add crossing zone 246 pet, t1, t2= moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold)
241 pet = moving.MovingObject.computePET(self.roadUser1, self.roadUser2, collisionDistanceThreshold) 247 if pet is not None:
242 if pet is not None: # TODO get crossing zone and time 248 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[10], {min(t1, t2): pet}, mostSevereIsMax = False))
243 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[10], {0: pet}, mostSevereIsMax = False))
244 249
245 def setCollision(self, collision): 250 def setCollision(self, collision):
246 '''indicates if it is a collision: argument should be boolean''' 251 '''indicates if it is a collision: argument should be boolean'''
247 self.collision = collision 252 self.collision = collision
248 253