Mercurial > hg > nsaunier > traffic-intelligence
comparison trafficintelligence/prediction.py @ 1104:1c59091853e0
generalization of motion prediction methods to curvilinear trajectories
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Mon, 11 Mar 2019 15:41:05 -0400 |
| parents | c6cf75a2ed08 |
| children | 2795d0e114c9 |
comparison
equal
deleted
inserted
replaced
| 1103:7594802f281a | 1104:1c59091853e0 |
|---|---|
| 263 prototypeTrajectories=findPrototypes(prototypes,nMatching,objects,route,partialObjPositions,noiseEntryNums,noiseExitNums,minSimilarity,mostMatched) | 263 prototypeTrajectories=findPrototypes(prototypes,nMatching,objects,route,partialObjPositions,noiseEntryNums,noiseExitNums,minSimilarity,mostMatched) |
| 264 return prototypeTrajectories | 264 return prototypeTrajectories |
| 265 | 265 |
| 266 | 266 |
| 267 class PredictionParameters(object): | 267 class PredictionParameters(object): |
| 268 def __init__(self, name, maxSpeed): | 268 def __init__(self, name, maxSpeed, useCurvilinear = False): |
| 269 self.name = name | 269 self.name = name |
| 270 self.maxSpeed = maxSpeed | 270 self.maxSpeed = maxSpeed |
| 271 self.useCurvilinear = useCurvilinear | |
| 271 | 272 |
| 272 def __str__(self): | 273 def __str__(self): |
| 273 return '{0} {1}'.format(self.name, self.maxSpeed) | 274 return '{0} {1}'.format(self.name, self.maxSpeed) |
| 274 | 275 |
| 275 def generatePredictedTrajectories(self, obj, instant): | 276 def generatePredictedTrajectories(self, obj, instant): |
| 521 class CVExactPredictionParameters(PredictionParameters): | 522 class CVExactPredictionParameters(PredictionParameters): |
| 522 '''Prediction parameters of prediction at constant velocity | 523 '''Prediction parameters of prediction at constant velocity |
| 523 using direct computation of the intersecting point (solving the equation) | 524 using direct computation of the intersecting point (solving the equation) |
| 524 Warning: the computed time to collision may be higher than timeHorizon (not used)''' | 525 Warning: the computed time to collision may be higher than timeHorizon (not used)''' |
| 525 | 526 |
| 526 def __init__(self): | 527 def __init__(self, useCurvilinear = False): |
| 527 PredictionParameters.__init__(self, 'constant velocity (direct exact computation)', None) | 528 PredictionParameters.__init__(self, 'constant velocity (direct exact computation)', None, useCurvilinear) |
| 528 | 529 |
| 529 def computeCrossingsCollisionsAtInstant(self, currentInstant, obj1, obj2, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, *kwargs): | 530 def computeCrossingsCollisionsAtInstant(self, currentInstant, obj1, obj2, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, *kwargs): |
| 530 'TODO compute pPET' | 531 'TODO compute pPET' |
| 531 collisionPoints = [] | 532 collisionPoints = [] |
| 532 crossingZones = [] | 533 crossingZones = [] |
| 533 | 534 |
| 534 p1 = obj1.getPositionAtInstant(currentInstant) | 535 if self.useCurvilinear: |
| 535 p2 = obj2.getPositionAtInstant(currentInstant) | 536 pass # Lionel |
| 536 v1 = obj1.getVelocityAtInstant(currentInstant) | 537 else: |
| 537 v2 = obj2.getVelocityAtInstant(currentInstant) | 538 p1 = obj1.getPositionAtInstant(currentInstant) |
| 538 #intersection = moving.intersection(p1, p1+v1, p2, p2+v2) | 539 p2 = obj2.getPositionAtInstant(currentInstant) |
| 539 | 540 v1 = obj1.getVelocityAtInstant(currentInstant) |
| 540 if not moving.Point.parallel(v1, v2): | 541 v2 = obj2.getVelocityAtInstant(currentInstant) |
| 541 ttc = moving.Point.timeToCollision(p1, p2, v1, v2, collisionDistanceThreshold) | 542 #intersection = moving.intersection(p1, p1+v1, p2, p2+v2) |
| 542 if ttc is not None: | 543 |
| 543 collisionPoints = [SafetyPoint((p1+(v1*ttc)+p2+(v2*ttc))*0.5, 1., ttc)] | 544 if not moving.Point.parallel(v1, v2): |
| 544 else: | 545 ttc = moving.Point.timeToCollision(p1, p2, v1, v2, collisionDistanceThreshold) |
| 545 pass # compute pPET | 546 if ttc is not None: |
| 547 collisionPoints = [SafetyPoint((p1+(v1*ttc)+p2+(v2*ttc))*0.5, 1., ttc)] | |
| 548 else: | |
| 549 pass # compute pPET | |
| 546 | 550 |
| 547 return collisionPoints, crossingZones | 551 return collisionPoints, crossingZones |
| 548 | 552 |
| 549 class PrototypePredictionParameters(PredictionParameters): | 553 class PrototypePredictionParameters(PredictionParameters): |
| 550 def __init__(self, prototypes, nPredictedTrajectories, pointSimilarityDistance, minSimilarity, lcssMetric = 'cityblock', minFeatureTime = 10, constantSpeed = False, useFeatures = True): | 554 def __init__(self, prototypes, nPredictedTrajectories, pointSimilarityDistance, minSimilarity, lcssMetric = 'cityblock', minFeatureTime = 10, constantSpeed = False, useFeatures = True): |
