Mercurial Hosting > traffic-intelligence
diff python/events.py @ 628:977407c9f815
corrected bugs in loading interactions (index shifted) and added functionalities to play/plot interactions
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 16 Feb 2015 11:58:51 +0100 |
parents | 82e9f78a4714 |
children | 0a5e89d6fc62 |
line wrap: on
line diff
--- a/python/events.py Mon Feb 16 08:41:14 2015 +0100 +++ b/python/events.py Mon Feb 16 11:58:51 2015 +0100 @@ -8,7 +8,7 @@ import multiprocessing import itertools -import moving, prediction, indicators, utils +import moving, prediction, indicators, utils, cvutils __metaclass__ = type def findRoute(prototypes,objects,i,j,noiseEntryNums,noiseExitNums,minSimilarity= 0.3, spatialThreshold=1.0, delta=180): @@ -61,7 +61,7 @@ 'Velocity Angle', 'Speed Differential', 'Collision Probability', - 'Time to Collision', + 'Time to Collision', # 7 'Probability of Successful Evasive Action', 'predicted Post Encroachment Time'] @@ -108,6 +108,22 @@ def getRoadUserNumbers(self): return self.roadUserNumbers + def setRoadUsers(self, objects): + nums = list(self.getRoadUserNumbers()) + if objects[nums[0]].getNum() == nums[0]: + self.roadUser1 = objects[nums[0]] + if objects[nums[1]].getNum() == nums[1]: + self.roadUser2 = objects[nums[1]] + + i = 0 + while i < len(objects) and self.roadUser2 == None: + if objects[i].getNum() in nums: + if self.roadUser1 == None: + self.roadUser1 = objects[i] + else: + self.roadUser2 = objects[i] + i += 1 + def getIndicator(self, indicatorName): return self.indicators.get(indicatorName, None) @@ -115,6 +131,20 @@ if indicator: self.indicators[indicator.name] = indicator + def plot(self, options = '', withOrigin = False, timeStep = 1, withFeatures = False, **kwargs): + self.roadUser1.plot(options, withOrigin, timeStep, withFeatures, **kwargs) + self.roadUser2.plot(options, withOrigin, timeStep, withFeatures, **kwargs) + + def plotOnWorldImage(self, nPixelsPerUnitDistance, options = '', withOrigin = False, timeStep = 1, **kwargs): + self.roadUser1.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) + self.roadUser2.plotOnWorldImage(nPixelsPerUnitDistance, options, withOrigin, timeStep, **kwargs) + + def play(self, videoFilename, homography = None, undistort = False, intrinsicCameraMatrix = None, distortionCoefficients = None, undistortedImageMultiplication = 1.): + if self.roadUser1 != None and self.roadUser2 != None: + cvutils.displayTrajectories(videoFilename, [self.roadUser1, self.roadUser2], homography = homography, firstFrameNum = self.getFirstInstant(), lastFrameNumArg = self.getLastInstant(), undistort = undistort, intrinsicCameraMatrix = intrinsicCameraMatrix, distortionCoefficients = distortionCoefficients, undistortedImageMultiplication = undistortedImageMultiplication) + else: + print('Please set the interaction road user attributes roadUser1 and roadUser1 through the method setRoadUsers') + def computeIndicators(self): '''Computes the collision course cosine only if the cosine is positive''' collisionCourseDotProducts = {}#[0]*int(self.timeInterval.length()) @@ -202,6 +232,16 @@ num += 1 return interactions +def findInteraction(interactions, roadUserNum1, roadUserNum2): + 'Returns the right interaction in the set' + i=0 + while i<len(interactions) and set([roadUserNum1, roadUserNum2]) != interactions[i].getRoadUserNumbers(): + i+=1 + if i<len(interactions): + return interactions[i] + else: + return None + def prototypeCluster(interactions, similarityMatrix, alignmentMatrix, indicatorName, minSimilarity): '''Finds exemplar indicator time series for all interactions Returns the prototype indices (in the interaction list) and the label of each indicator (interaction)