Mercurial Hosting > traffic-intelligence
comparison scripts/safety-analysis.py @ 483:30b3455978d9
Corrected issues with safety-analysis script, variable names are changed and tracking.cfg accordingly
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 02 Apr 2014 17:25:50 -0400 |
parents | f6415f012640 |
children | a5847c0ca27c |
comparison
equal
deleted
inserted
replaced
482:f6415f012640 | 483:30b3455978d9 |
---|---|
1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
2 | 2 |
3 import utils, storage, prediction, events, moving | 3 import utils, storage, prediction, events, moving |
4 | 4 |
5 import sys, argparse | 5 import sys, argparse, random |
6 | 6 |
7 import matplotlib.pyplot as plt | 7 import matplotlib.pyplot as plt |
8 import numpy as np | 8 import numpy as np |
9 | 9 |
10 # todo: very slow if too many predicted trajectories | 10 # todo: very slow if too many predicted trajectories |
11 # add computation of probality of unsucessful evasive action | 11 # add computation of probality of unsucessful evasive action |
12 | 12 |
13 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') | 13 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene') |
14 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file') | 14 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) |
15 parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (vector computation), constant velocity, normal adaptation, point set prediction)', choices = ['cvd', 'cv', 'na', 'ps']) | 15 parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (vector computation), constant velocity, normal adaptation, point set prediction)', choices = ['cvd', 'cv', 'na', 'ps']) |
16 parser.add_argument('--display-cp', dest = 'displayCollisionPoints', help = 'display collision points', action = 'store_true') | 16 parser.add_argument('--display-cp', dest = 'displayCollisionPoints', help = 'display collision points', action = 'store_true') |
17 args = parser.parse_args() | 17 args = parser.parse_args() |
18 | 18 |
19 params = utils.TrackingParameters() | 19 params = utils.TrackingParameters() |
23 if args.predictionMethod: | 23 if args.predictionMethod: |
24 predictionMethod = args.predictionMethod | 24 predictionMethod = args.predictionMethod |
25 else: | 25 else: |
26 predictionMethod = params.predictionMethod | 26 predictionMethod = params.predictionMethod |
27 | 27 |
28 accelerationDistribution = lambda: random.triangular(-params.maxNormalAcceleration, params.maxNormalAcceleration, 0.) | |
29 steeringDistribution = lambda: random.triangular(-params.maxNormalSteering, params.maxNormalSteering, 0.) | |
30 | |
28 if predictionMethod == 'cvd': | 31 if predictionMethod == 'cvd': |
29 predictionParameters = prediction.CVDirectPredictionParameters() | 32 predictionParameters = prediction.CVDirectPredictionParameters() |
30 elif predictionMethod == 'cv': | 33 elif predictionMethod == 'cv': |
31 predictionParameters = prediction.ConstantPredictionParameters(params.maxPredictedSpeed) | 34 predictionParameters = prediction.ConstantPredictionParameters(params.maxPredictedSpeed) |
32 elif predictionMethod == 'na': | 35 elif predictionMethod == 'na': |
33 predictionParameters = prediction.NormalAdaptationPredictionParameters(params.maxPredictedSpeed, | 36 predictionParameters = prediction.NormalAdaptationPredictionParameters(params.maxPredictedSpeed, |
34 params.nPredictedTrajectories, | 37 params.nPredictedTrajectories, |
35 params.maxAcceleration, | 38 accelerationDistribution, |
36 params.maxSteering, | 39 steeringDistribution, |
37 params.useFeaturesForPrediction) | 40 params.useFeaturesForPrediction) |
38 elif predictionMethod == 'ps': | 41 elif predictionMethod == 'ps': |
39 predictionParameters = prediction.PointSetPredictionParameters(params.nPredictedTrajectories, | 42 predictionParameters = prediction.PointSetPredictionParameters(params.nPredictedTrajectories, |
40 params.maxPredictedSpeed) | 43 params.maxPredictedSpeed) |
41 else: | 44 # no else required, since parameters is required as argument |
42 print('Prediction method {} is not valid. See help.'.format(predictionMethod)) | |
43 sys.exit() | |
44 | 45 |
45 # evasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(params.maxPredictedSpeed, | 46 # evasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(params.maxPredictedSpeed, |
46 # params.nPredictedTrajectories, | 47 # params.nPredictedTrajectories, |
47 # params.minAcceleration, | 48 # params.minExtremeAcceleration, |
48 # params.maxAcceleration, | 49 # params.maxExtremeAcceleration, |
49 # params.maxSteering, | 50 # params.maxExtremeSteering, |
50 # params.useFeaturesForPrediction) | 51 # params.useFeaturesForPrediction) |
51 | 52 |
52 objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'object') | 53 objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'object') |
53 if params.useFeaturesForPrediction: | 54 if params.useFeaturesForPrediction: |
54 features = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'feature') # needed if normal adaptation | 55 features = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'feature') # needed if normal adaptation |
56 obj.setFeatures(features) | 57 obj.setFeatures(features) |
57 | 58 |
58 interactions = events.createInteractions(objects) | 59 interactions = events.createInteractions(objects) |
59 for inter in interactions: | 60 for inter in interactions: |
60 inter.computeIndicators() | 61 inter.computeIndicators() |
61 inter.computeCrossingsCollisions(predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones) | 62 inter.computeCrossingsCollisions(predictionParameters, params.collisionDistance, params.predictionTimeHorizon*params.videoFrameRate, params.crossingZones) |
62 | 63 |
63 storage.saveIndicators(params.databaseFilename, interactions) | 64 storage.saveIndicators(params.databaseFilename, interactions) |
64 | 65 |
65 if args.displayCollisionPoints: | 66 if args.displayCollisionPoints: |
66 plt.figure() | 67 plt.figure() |