Mercurial > hg > nsaunier > traffic-intelligence
comparison scripts/safety-analysis.py @ 943:b1e8453c207c
work on motion prediction using motion patterns
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 19 Jul 2017 18:02:38 -0400 |
| parents | a2f3f3ca241e |
| children | 84ebe1b031f1 |
comparison
equal
deleted
inserted
replaced
| 942:ab13aaf41432 | 943:b1e8453c207c |
|---|---|
| 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', required = True) | 14 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True) |
| 15 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to analyse', type = int) | 15 parser.add_argument('-n', dest = 'nObjects', help = 'number of objects to analyse', type = int) |
| 16 # TODO analyze only | 16 # TODO analyze only |
| 17 parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (cvd: vector computation (approximate); cve: equation solving; cv: discrete time (approximate)), normal adaptation, point set prediction)', choices = ['cvd', 'cve', 'cv', 'na', 'ps', 'proto']) | 17 parser.add_argument('--prediction-method', dest = 'predictionMethod', help = 'prediction method (constant velocity (cvd: vector computation (approximate); cve: equation solving; cv: discrete time (approximate)), normal adaptation, point set prediction)', choices = ['cvd', 'cve', 'cv', 'na', 'ps', 'mp']) |
| 18 parser.add_argument('--cfg', dest = 'prototypeDatabaseFilename', help = 'name of the database containing the prototypes') | 18 parser.add_argument('--prototypeDatabaseFilename', dest = 'prototypeDatabaseFilename', help = 'name of the database containing the prototypes') |
| 19 parser.add_argument('--pet', dest = 'computePET', help = 'computes PET', action = 'store_true') | 19 parser.add_argument('--pet', dest = 'computePET', help = 'computes PET', action = 'store_true') |
| 20 parser.add_argument('--display-cp', dest = 'displayCollisionPoints', help = 'display collision points', action = 'store_true') | 20 parser.add_argument('--display-cp', dest = 'displayCollisionPoints', help = 'display collision points', action = 'store_true') |
| 21 parser.add_argument('--nthreads', dest = 'nProcesses', help = 'number of processes to run in parallel', type = int, default = 1) | 21 parser.add_argument('--nthreads', dest = 'nProcesses', help = 'number of processes to run in parallel', type = int, default = 1) |
| 22 args = parser.parse_args() | 22 args = parser.parse_args() |
| 23 | 23 |
| 46 accelerationDistribution, | 46 accelerationDistribution, |
| 47 steeringDistribution, | 47 steeringDistribution, |
| 48 params.useFeaturesForPrediction) | 48 params.useFeaturesForPrediction) |
| 49 elif predictionMethod == 'ps': | 49 elif predictionMethod == 'ps': |
| 50 predictionParameters = prediction.PointSetPredictionParameters(params.maxPredictedSpeed) | 50 predictionParameters = prediction.PointSetPredictionParameters(params.maxPredictedSpeed) |
| 51 elif predictionMethod == 'proto': | 51 elif predictionMethod == 'mp': |
| 52 prototypes = storage.loadPrototypesFromSqlite(args.prototypeDatabaseFilename) | 52 if args.prototypeDatabaseFilename is None: |
| 53 prototypes = storage.loadPrototypesFromSqlite(params.databaseFilename) | |
| 54 else: | |
| 55 prototypes = storage.loadPrototypesFromSqlite(args.prototypeDatabaseFilename) | |
| 53 for p in prototypes: | 56 for p in prototypes: |
| 54 p.getMovingObject().getPositions().computeCumulativeDistances() | 57 p.getMovingObject().computeCumulativeDistances() |
| 58 predictionParameters = prediction.PrototypePredictionParameters(prototypes, params.nPredictedTrajectories, 2., 0.5, 'cityblock', 10, params.constantSpeedPrototypePrediction, params.useFeaturesForPrediction) | |
| 59 # else: | |
| 55 # no else required, since parameters is required as argument | 60 # no else required, since parameters is required as argument |
| 56 | 61 |
| 57 # evasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(params.maxPredictedSpeed, | 62 # evasiveActionPredictionParameters = prediction.EvasiveActionPredictionParameters(params.maxPredictedSpeed, |
| 58 # params.nPredictedTrajectories, | 63 # params.nPredictedTrajectories, |
| 59 # params.minExtremeAcceleration, | 64 # params.minExtremeAcceleration, |
| 60 # params.maxExtremeAcceleration, | 65 # params.maxExtremeAcceleration, |
| 61 # params.maxExtremeSteering, | 66 # params.maxExtremeSteering, |
| 62 # params.useFeaturesForPrediction) | 67 # params.useFeaturesForPrediction) |
| 63 | 68 |
| 64 objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename, 'object', args.nObjects, withFeatures = (params.useFeaturesForPrediction or (predictionMethod == 'ps'))) | 69 objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename, 'object', args.nObjects, withFeatures = (params.useFeaturesForPrediction or predictionMethod == 'ps' or predictionMethod == 'mp')) |
| 65 # if params.useFeaturesForPrediction: | 70 # if params.useFeaturesForPrediction: |
| 66 # features = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'feature') # needed if normal adaptation | 71 # features = storage.loadTrajectoriesFromSqlite(params.databaseFilename,'feature') # needed if normal adaptation |
| 67 # for obj in objects: | 72 # for obj in objects: |
| 68 # obj.setFeatures(features) | 73 # obj.setFeatures(features) |
| 69 | 74 |
| 70 interactions = events.createInteractions(objects) | 75 interactions = events.createInteractions(objects) |
| 71 for inter in interactions: | 76 for inter in interactions: |
| 72 inter.computeIndicators() | 77 inter.computeIndicators() |
| 73 inter.computeCrossingsCollisions(predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones, nProcesses = args.nProcesses) | 78 inter.computeCrossingsCollisions(predictionParameters, params.collisionDistance, params.predictionTimeHorizon, params.crossingZones, nProcesses = args.nProcesses, debug = True) |
| 74 | 79 |
| 75 if args.computePET: | 80 if args.computePET: |
| 76 for inter in interactions: | 81 for inter in interactions: |
| 77 inter.computePET(params.collisionDistance) | 82 inter.computePET(params.collisionDistance) |
| 78 | 83 |
