Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/prediction.py @ 1154:2795d0e114c9
deal with possibility of prototype with speed 0 that crashes motion prediction
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 09 Sep 2020 16:28:38 -0400 |
parents | 1c59091853e0 |
children | 2064e52019db |
comparison
equal
deleted
inserted
replaced
1153:f52844c71454 | 1154:2795d0e114c9 |
---|---|
67 ''' prototype is a MovingObject | 67 ''' prototype is a MovingObject |
68 | 68 |
69 Prediction at constant speed will not work for unrealistic trajectories | 69 Prediction at constant speed will not work for unrealistic trajectories |
70 that do not follow a slowly changing velocity (eg moving object trajectories, | 70 that do not follow a slowly changing velocity (eg moving object trajectories, |
71 but is good for realistic motion (eg features)''' | 71 but is good for realistic motion (eg features)''' |
72 self.valid = True | |
72 self.prototype = prototype | 73 self.prototype = prototype |
73 self.constantSpeed = constantSpeed | 74 self.constantSpeed = constantSpeed |
74 self.nFramesIgnore = nFramesIgnore | 75 self.nFramesIgnore = nFramesIgnore |
75 self.probability = probability | 76 self.probability = probability |
76 self.predictedPositions = {0: initialPosition} | 77 self.predictedPositions = {0: initialPosition} |
77 self.closestPointIdx = prototype.getPositions().getClosestPoint(initialPosition) | 78 self.closestPointIdx = prototype.getPositions().getClosestPoint(initialPosition) |
78 self.deltaPosition = initialPosition-prototype.getPositionAt(self.closestPointIdx) #should be computed in relative coordinates to position | 79 self.deltaPosition = initialPosition-prototype.getPositionAt(self.closestPointIdx) #should be computed in relative coordinates to position |
79 self.theta = prototype.getVelocityAt(self.closestPointIdx).angle() | 80 self.theta = prototype.getVelocityAt(self.closestPointIdx).angle() |
80 self.initialSpeed = initialVelocity.norm2() | 81 self.initialSpeed = initialVelocity.norm2() |
81 if not constantSpeed: | 82 if not constantSpeed: |
82 self.ratio = self.initialSpeed/prototype.getVelocityAt(self.closestPointIdx).norm2() | 83 while prototype.getVelocityAt(self.closestPointIdx).norm2() == 0. and self.closestPointIdx < prototype.length(): |
84 self.closestPointIdx += 1 | |
85 if self.closestPointIdx < prototype.length(): | |
86 self.ratio = self.initialSpeed/prototype.getVelocityAt(self.closestPointIdx).norm2() | |
87 else: | |
88 self.valid = False | |
83 | 89 |
84 def predictPosition(self, nTimeSteps): | 90 def predictPosition(self, nTimeSteps): |
85 if nTimeSteps > 0 and not nTimeSteps in self.predictedPositions: | 91 if nTimeSteps > 0 and not nTimeSteps in self.predictedPositions: |
86 deltaPosition = copy(self.deltaPosition) | 92 deltaPosition = copy(self.deltaPosition) |
87 if self.constantSpeed: | 93 if self.constantSpeed: |
568 obj.computeTrajectorySimilarities(self.prototypes, self.lcss) | 574 obj.computeTrajectorySimilarities(self.prototypes, self.lcss) |
569 for proto, similarities in zip(self.prototypes, obj.prototypeSimilarities): | 575 for proto, similarities in zip(self.prototypes, obj.prototypeSimilarities): |
570 if similarities[instant-obj.getFirstInstant()] >= self.minSimilarity: | 576 if similarities[instant-obj.getFirstInstant()] >= self.minSimilarity: |
571 initialPosition = obj.getPositionAtInstant(instant) | 577 initialPosition = obj.getPositionAtInstant(instant) |
572 initialVelocity = obj.getVelocityAtInstant(instant) | 578 initialVelocity = obj.getVelocityAtInstant(instant) |
573 predictedTrajectories.append(PredictedTrajectoryPrototype(initialPosition, initialVelocity, proto.getMovingObject(), constantSpeed = self.constantSpeed, probability = proto.getNMatchings())) | 579 predictedTrajectory = PredictedTrajectoryPrototype(initialPosition, initialVelocity, proto.getMovingObject(), constantSpeed = self.constantSpeed, probability = proto.getNMatchings()) |
580 if predictedTrajectory.valid: | |
581 predictedTrajectories.append(predictedTrajectory) | |
574 | 582 |
575 def generatePredictedTrajectories(self, obj, instant): | 583 def generatePredictedTrajectories(self, obj, instant): |
576 predictedTrajectories = [] | 584 predictedTrajectories = [] |
577 if instant-obj.getFirstInstant()+1 >= self.minFeatureTime: | 585 if instant-obj.getFirstInstant()+1 >= self.minFeatureTime: |
578 if self.useFeatures and obj.hasFeatures(): | 586 if self.useFeatures and obj.hasFeatures(): |