Mercurial Hosting > traffic-intelligence
comparison python/events.py @ 636:3058e00887bc
removed all issues because of tests with None, using is instead of == or !=
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 24 Mar 2015 18:11:28 +0100 |
parents | 2f1a583bfd20 |
children | dc70d9e711f5 |
comparison
equal
deleted
inserted
replaced
635:6ae68383071e | 636:3058e00887bc |
---|---|
89 '', | 89 '', |
90 ''] | 90 ''] |
91 | 91 |
92 def __init__(self, num = None, timeInterval = None, roaduserNum1 = None, roaduserNum2 = None, roadUser1 = None, roadUser2 = None, categoryNum = None): | 92 def __init__(self, num = None, timeInterval = None, roaduserNum1 = None, roaduserNum2 = None, roadUser1 = None, roadUser2 = None, categoryNum = None): |
93 moving.STObject.__init__(self, num, timeInterval) | 93 moving.STObject.__init__(self, num, timeInterval) |
94 if timeInterval == None and roadUser1 != None and roadUser2 != None: | 94 if timeInterval is None and roadUser1 is not None and roadUser2 is not None: |
95 self.timeInterval = roadUser1.commonTimeInterval(roadUser2) | 95 self.timeInterval = roadUser1.commonTimeInterval(roadUser2) |
96 self.roadUser1 = roadUser1 | 96 self.roadUser1 = roadUser1 |
97 self.roadUser2 = roadUser2 | 97 self.roadUser2 = roadUser2 |
98 if roaduserNum1 != None and roaduserNum2 != None: | 98 if roaduserNum1 is not None and roaduserNum2 is not None: |
99 self.roadUserNumbers = set([roaduserNum1, roaduserNum2]) | 99 self.roadUserNumbers = set([roaduserNum1, roaduserNum2]) |
100 elif roadUser1 != None and roadUser2 != None: | 100 elif roadUser1 is not None and roadUser2 is not None: |
101 self.roadUserNumbers = set(roadUser1.getNum(), roadUser2.getNum()) | 101 self.roadUserNumbers = set(roadUser1.getNum(), roadUser2.getNum()) |
102 else: | 102 else: |
103 self.roadUserNumbers = None | 103 self.roadUserNumbers = None |
104 self.categoryNum = categoryNum | 104 self.categoryNum = categoryNum |
105 self.indicators = {} | 105 self.indicators = {} |
114 self.roadUser1 = objects[nums[0]] | 114 self.roadUser1 = objects[nums[0]] |
115 if objects[nums[1]].getNum() == nums[1]: | 115 if objects[nums[1]].getNum() == nums[1]: |
116 self.roadUser2 = objects[nums[1]] | 116 self.roadUser2 = objects[nums[1]] |
117 | 117 |
118 i = 0 | 118 i = 0 |
119 while i < len(objects) and self.roadUser2 == None: | 119 while i < len(objects) and self.roadUser2 is None: |
120 if objects[i].getNum() in nums: | 120 if objects[i].getNum() in nums: |
121 if self.roadUser1 == None: | 121 if self.roadUser1 is None: |
122 self.roadUser1 = objects[i] | 122 self.roadUser1 = objects[i] |
123 else: | 123 else: |
124 self.roadUser2 = objects[i] | 124 self.roadUser2 = objects[i] |
125 i += 1 | 125 i += 1 |
126 | 126 |
138 def plotOnWorldImage(self, nPixelsPerUnitDistance, options = '', withOrigin = False, timeStep = 1, **kwargs): | 138 def plotOnWorldImage(self, nPixelsPerUnitDistance, options = '', withOrigin = False, timeStep = 1, **kwargs): |
139 self.roadUser1.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) | 139 self.roadUser1.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) |
140 self.roadUser2.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) | 140 self.roadUser2.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) |
141 | 141 |
142 def play(self, videoFilename, homography = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1.): | 142 def play(self, videoFilename, homography = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1.): |
143 if self.roadUser1 != None and self.roadUser2 != None: | 143 if self.roadUser1 is not None and self.roadUser2 is not None: |
144 cvutils.displayTrajectories(videoFilename, [self.roadUser1, self.roadUser2], homography = homography, firstFrameNum = self.getFirstInstant(), lastFrameNumArg = self.getLastInstant(), undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) | 144 cvutils.displayTrajectories(videoFilename, [self.roadUser1, self.roadUser2], homography = homography, firstFrameNum = self.getFirstInstant(), lastFrameNumArg = self.getLastInstant(), undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) |
145 else: | 145 else: |
146 print('Please set the interaction road user attributes roadUser1 and roadUser1 through the method setRoadUsers') | 146 print('Please set the interaction road user attributes roadUser1 and roadUser1 through the method setRoadUsers') |
147 | 147 |
148 def computeIndicators(self): | 148 def computeIndicators(self): |
190 TTCs = {} | 190 TTCs = {} |
191 if usePrototypes: | 191 if usePrototypes: |
192 route1= getRoute(self.roadUser1,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination) | 192 route1= getRoute(self.roadUser1,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination) |
193 route2= getRoute(self.roadUser2,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination) | 193 route2= getRoute(self.roadUser2,prototypes,objects,noiseEntryNums,noiseExitNums,useDestination) |
194 | 194 |
195 if timeInterval != None: | 195 if timeInterval is not None: |
196 commonTimeInterval = timeInterval | 196 commonTimeInterval = timeInterval |
197 else: | 197 else: |
198 commonTimeInterval = self.timeInterval | 198 commonTimeInterval = self.timeInterval |
199 self.collisionPoints, self.crossingZones = predictionParameters.computeCrossingsCollisions(self.roadUser1, self.roadUser2, collisionDistanceThreshold, timeHorizon, computeCZ, debug, commonTimeInterval, nProcesses,usePrototypes,route1,route2,prototypes,secondStepPrototypes,nMatching,objects,noiseEntryNums,noiseExitNums,minSimilarity,mostMatched,useDestination,useSpeedPrototype,acceptPartialLength, step) | 199 self.collisionPoints, self.crossingZones = predictionParameters.computeCrossingsCollisions(self.roadUser1, self.roadUser2, collisionDistanceThreshold, timeHorizon, computeCZ, debug, commonTimeInterval, nProcesses,usePrototypes,route1,route2,prototypes,secondStepPrototypes,nMatching,objects,noiseEntryNums,noiseExitNums,minSimilarity,mostMatched,useDestination,useSpeedPrototype,acceptPartialLength, step) |
200 for i, cp in self.collisionPoints.iteritems(): | 200 for i, cp in self.collisionPoints.iteritems(): |
219 ''' interaction types: conflict or collision if they are known''' | 219 ''' interaction types: conflict or collision if they are known''' |
220 self.interactionType= interactionType | 220 self.interactionType= interactionType |
221 | 221 |
222 def createInteractions(objects, _others = None): | 222 def createInteractions(objects, _others = None): |
223 '''Create all interactions of two co-existing road users''' | 223 '''Create all interactions of two co-existing road users''' |
224 if _others != None: | 224 if _others is not None: |
225 others = _others | 225 others = _others |
226 | 226 |
227 interactions = [] | 227 interactions = [] |
228 num = 0 | 228 num = 0 |
229 for i in xrange(len(objects)): | 229 for i in xrange(len(objects)): |
230 if _others == None: | 230 if _others is None: |
231 others = objects[:i] | 231 others = objects[:i] |
232 for j in xrange(len(others)): | 232 for j in xrange(len(others)): |
233 commonTimeInterval = objects[i].commonTimeInterval(others[j]) | 233 commonTimeInterval = objects[i].commonTimeInterval(others[j]) |
234 if not commonTimeInterval.empty(): | 234 if not commonTimeInterval.empty(): |
235 interactions.append(Interaction(num, commonTimeInterval, objects[i].num, others[j].num, objects[i], others[j])) | 235 interactions.append(Interaction(num, commonTimeInterval, objects[i].num, others[j].num, objects[i], others[j])) |