Mercurial Hosting > traffic-intelligence
comparison python/events.py @ 604:8ba4b8ad4c86
Motion Pattern Method
author | MohamedGomaa |
---|---|
date | Tue, 15 Jul 2014 13:25:15 -0400 |
parents | 21bdeb29f855 |
children |
comparison
equal
deleted
inserted
replaced
548:e6ab4caf359c | 604:8ba4b8ad4c86 |
---|---|
1 #! /usr/bin/env python | 1 #! /usr/bin/env python |
2 '''Libraries for events | 2 '''Libraries for events |
3 Interactions, pedestrian crossing...''' | 3 Interactions, pedestrian crossing...''' |
4 | 4 import sys |
5 import numpy as np | 5 import numpy as np |
6 from numpy import arccos | 6 from numpy import arccos |
7 | 7 |
8 import multiprocessing | 8 import multiprocessing |
9 import itertools | 9 import itertools |
136 | 136 |
137 if computeCZ: | 137 if computeCZ: |
138 pPETs = {} | 138 pPETs = {} |
139 for i in list(commonTimeInterval)[:-1]: | 139 for i in list(commonTimeInterval)[:-1]: |
140 if len(self.crossingZones[i]) > 0: | 140 if len(self.crossingZones[i]) > 0: |
141 pPETs[i] = prediction.SafetyPoint.computeExpectedIndicator(self.crossingZones[i]) | |
142 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[9], pPETs)) | |
143 | |
144 def computeCrossingsCollisionsPrototype(self, predictionParameters, collisionDistanceThreshold, timeHorizon, prototypes,nMatching,objects,minSimilarity=0.5,index=None,mostMatched=None, computeCZ = False, debug = False, timeInterval = None,acceptPartialLength=30): | |
145 '''Computes all crossing and collision points at each common instant for two road users. ''' | |
146 self.collisionPoints={} | |
147 self.crossingZones={} | |
148 TTCs = {} | |
149 route1=(self.roadUser1.startRouteID,self.roadUser1.endRouteID) | |
150 route2=(self.roadUser2.startRouteID,self.roadUser2.endRouteID) | |
151 | |
152 if timeInterval: | |
153 commonTimeInterval = timeInterval | |
154 else: | |
155 commonTimeInterval = self.timeInterval | |
156 for i in list(commonTimeInterval)[:-1]: # do not look at the 1 last position/velocities, often with errors | |
157 sys.path.append("D:/behaviourAnalysis/libs") | |
158 import trajLearning | |
159 if i-self.roadUser1.timeInterval.first >= acceptPartialLength and i-self.roadUser2.timeInterval.first >= acceptPartialLength: | |
160 inter1=moving.Interval(self.roadUser1.timeInterval.first,i) | |
161 inter2=moving.Interval(self.roadUser2.timeInterval.first,i) | |
162 partialObjPositions1= self.roadUser1.getObjectInTimeInterval(inter1).positions | |
163 partialObjPositions2= self.roadUser2.getObjectInTimeInterval(inter2).positions | |
164 prototypeTrajectories1=trajLearning.findPrototypes(prototypes,nMatching,objects,route1,partialObjPositions1,minSimilarity,index,mostMatched) | |
165 prototypeTrajectories2=trajLearning.findPrototypes(prototypes,nMatching,objects,route2,partialObjPositions2,minSimilarity,index,mostMatched) | |
166 if prototypeTrajectories1=={}: | |
167 print self.roadUser1.num, 'is abnormal at instant', str(i) | |
168 elif prototypeTrajectories2=={}: | |
169 print self.roadUser2.num, 'is abnormal at instant', str(i) | |
170 else: | |
171 self.collisionPoints[i], self.crossingZones[i] = predictionParameters.computeCrossingsCollisionsAtInstant(i, self.roadUser1, self.roadUser2, collisionDistanceThreshold, timeHorizon, computeCZ, debug,prototypeTrajectories1,prototypeTrajectories2) | |
172 if len(self.collisionPoints[i]) > 0: | |
173 TTCs[i] = prediction.SafetyPoint.computeExpectedIndicator(self.collisionPoints[i]) | |
174 # add probability of collision, and probability of successful evasive action | |
175 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[7], TTCs)) | |
176 | |
177 if computeCZ: | |
178 pPETs = {} | |
179 for i in list(commonTimeInterval)[:-1]: | |
180 if i in self.crossingZones.keys() and len(self.crossingZones[i]) > 0: | |
141 pPETs[i] = prediction.SafetyPoint.computeExpectedIndicator(self.crossingZones[i]) | 181 pPETs[i] = prediction.SafetyPoint.computeExpectedIndicator(self.crossingZones[i]) |
142 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[9], pPETs)) | 182 self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[9], pPETs)) |
143 | 183 |
144 def addVideoFilename(self,videoFilename): | 184 def addVideoFilename(self,videoFilename): |
145 self.videoFilename= videoFilename | 185 self.videoFilename= videoFilename |