Mercurial Hosting > traffic-intelligence
changeset 345:fa64b2e3a64f
added simple classification based on speed
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 25 Jun 2013 23:43:32 -0400 |
parents | 14a2405f54f8 |
children | 5f75d6c23ed5 |
files | python/moving.py python/tests/moving.txt |
diffstat | 2 files changed, 23 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/python/moving.py Fri Jun 21 17:32:57 2013 -0400 +++ b/python/moving.py Tue Jun 25 23:43:32 2013 -0400 @@ -5,6 +5,7 @@ import cvutils from math import sqrt +from numpy import median #from shapely.geometry import Polygon @@ -582,9 +583,10 @@ with a trajectory and a geometry (constant volume over time) and a usertype (e.g. road user) coded as a number (see ''' - def __init__(self, num = None, timeInterval = None, positions = None, geometry = None, userType = None): + def __init__(self, num = None, timeInterval = None, positions = None, velocities = None, geometry = None, userType = None): super(MovingObject, self).__init__(num, timeInterval) self.positions = positions + self.velocities = velocities self.geometry = geometry self.userType = userType self.features = None @@ -670,6 +672,15 @@ at constant speed''' return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) + def classifyUserTypeSpeed(self, threshold, statisticsFunc = median): + '''Classifies slow and fast road users + slow: non-motorized -> pedestrians + fast: motorized -> cars''' + if statisticsFunc(self.velocities.norm()) >= threshold: + self.setUserType(userType2Num['car']) + else: + self.setUserType(userType2Num['pedestrian']) + @staticmethod def collisionCourseDotProduct(movingObject1, movingObject2, instant): 'A positive result indicates that the road users are getting closer'
--- a/python/tests/moving.txt Fri Jun 21 17:32:57 2013 -0400 +++ b/python/tests/moving.txt Tue Jun 25 23:43:32 2013 -0400 @@ -79,3 +79,14 @@ 3 >>> Trajectory.normMaxLCSS(t1, t1, 0.1) 3 + +>>> o1 = MovingObject(positions = Trajectory([[0]*3,[2]*3]), velocities = Trajectory([[0]*3,[1]*3])) +>>> o1.classifyUserTypeSpeed(0.5, np.median) +>>> userTypeNames[o1.getUserType()] +'car' +>>> o1.classifyUserTypeSpeed(0.5, np.mean) +>>> userTypeNames[o1.getUserType()] +'car' +>>> o1.classifyUserTypeSpeed(1.5, np.median) +>>> userTypeNames[o1.getUserType()] +'pedestrian'