Mercurial Hosting > traffic-intelligence
changeset 357:e5fe0e6d48a1
corrected bug computing TTC (resp. pPET) if there is no collision point (resp. crossing zone)
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 11 Jul 2013 00:07:47 -0400 |
parents | 15fac9c45feb |
children | c41ff9f3c263 |
files | python/events.py python/moving.py python/prediction.py scripts/safety-analysis.py |
diffstat | 4 files changed, 25 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/python/events.py Wed Jul 10 18:22:45 2013 -0400 +++ b/python/events.py Thu Jul 11 00:07:47 2013 -0400 @@ -118,15 +118,17 @@ commonTimeInterval = self.timeInterval for i in list(commonTimeInterval)[:-1]: # do not look at the 1 last position/velocities, often with errors self.collisionPoints[i], self.crossingZones[i] = prediction.computeCrossingsCollisionsAtInstant(i, self.roadUser1, self.roadUser2, predictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ, debug) - TTCs[i] = prediction.computeExpectedIndicator(self.collisionPoints[i]) + if len(self.collisionPoints[i]) > 0: + TTCs[i] = prediction.computeExpectedIndicator(self.collisionPoints[i]) # add probability of collision, and probability of successful evasive action self.addIndicator(indicators.SeverityIndicator('TTC', TTCs)) if computeCZ: pPETs = {} for i in list(commonTimeInterval)[:-1]: - pPETs[i] = prediction.computeExpectedIndicator(self.crossingZones[i]) - self.addIndicator(indicators.SeverityIndicator('pPET', pPETs)) + if len(self.crossingZones[i]) > 0: + pPETs[i] = prediction.computeExpectedIndicator(self.crossingZones[i]) + self.addIndicator(indicators.SeverityIndicator('pPET', pPETs)) def addVideoFilename(self,videoFilename): self.videoFilename= videoFilename
--- a/python/moving.py Wed Jul 10 18:22:45 2013 -0400 +++ b/python/moving.py Thu Jul 11 00:07:47 2013 -0400 @@ -238,9 +238,9 @@ return (p1-p2).norm2() @staticmethod - def plotAll(points, color='r'): + def plotAll(points, **kwargs): from matplotlib.pyplot import scatter - scatter([p.x for p in points],[p.y for p in points], c=color) + scatter([p.x for p in points],[p.y for p in points], **kwargs) class NormAngle(object): '''Alternate encoding of a point, by its norm and orientation'''
--- a/python/prediction.py Wed Jul 10 18:22:45 2013 -0400 +++ b/python/prediction.py Thu Jul 11 00:07:47 2013 -0400 @@ -306,6 +306,13 @@ return collisionProbabilities +#### +# Other Methods +#### + + + + if __name__ == "__main__": import doctest
--- a/scripts/safety-analysis.py Wed Jul 10 18:22:45 2013 -0400 +++ b/scripts/safety-analysis.py Thu Jul 11 00:07:47 2013 -0400 @@ -1,15 +1,19 @@ #! /usr/bin/env python -import utils, storage, prediction, events +import utils, storage, prediction, events, moving import sys, argparse import matplotlib.pyplot as plt import numpy as np +# todo: very slow if too many predicted trajectories +# add computation of probality of unsucessful evasive action + parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity, normal adaptation, point set prediction)', choices = ['cv', 'na', 'ps']) +parser.add_argument('--display-cp', dest = 'displayCollisionPoints', help = 'display collision points') args = parser.parse_args() params = utils.TrackingParameters() @@ -50,17 +54,18 @@ obj.setFeatures(features) interactions = events.createInteractions(objects) -for inter in interactions[:1]: +for inter in interactions: inter.computeIndicators() inter.computeCrossingsCollisions(predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones) storage.saveIndicators(params.databaseFilename, interactions) -if False: +if args.displayCollisionPoints: plt.figure() - plt.axis('equal') + allCollisionPoints = [] for inter in interactions: for collisionPoints in inter.collisionPoints.values(): - for cp in collisionPoints: - plt.plot([cp.x], [cp.y], 'x') + allCollisionPoints += collisionPoints + moving.Point.plotAll(allCollisionPoints) + plt.axis('equal')