comparison python/moving.py @ 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 74e437ab5f11
children e5fe0e6d48a1
comparison
equal deleted inserted replaced
344:14a2405f54f8 345:fa64b2e3a64f
3 3
4 import utils 4 import utils
5 import cvutils 5 import cvutils
6 6
7 from math import sqrt 7 from math import sqrt
8 from numpy import median
8 9
9 #from shapely.geometry import Polygon 10 #from shapely.geometry import Polygon
10 11
11 __metaclass__ = type 12 __metaclass__ = type
12 13
580 class MovingObject(STObject): 581 class MovingObject(STObject):
581 '''Class for moving objects: a spatio-temporal object 582 '''Class for moving objects: a spatio-temporal object
582 with a trajectory and a geometry (constant volume over time) and a usertype (e.g. road user) coded as a number (see 583 with a trajectory and a geometry (constant volume over time) and a usertype (e.g. road user) coded as a number (see
583 ''' 584 '''
584 585
585 def __init__(self, num = None, timeInterval = None, positions = None, geometry = None, userType = None): 586 def __init__(self, num = None, timeInterval = None, positions = None, velocities = None, geometry = None, userType = None):
586 super(MovingObject, self).__init__(num, timeInterval) 587 super(MovingObject, self).__init__(num, timeInterval)
587 self.positions = positions 588 self.positions = positions
589 self.velocities = velocities
588 self.geometry = geometry 590 self.geometry = geometry
589 self.userType = userType 591 self.userType = userType
590 self.features = None 592 self.features = None
591 # compute bounding polygon from trajectory 593 # compute bounding polygon from trajectory
592 594
668 def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)): 670 def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)):
669 '''Predicts the position of object at instant+deltaT, 671 '''Predicts the position of object at instant+deltaT,
670 at constant speed''' 672 at constant speed'''
671 return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) 673 return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration)
672 674
675 def classifyUserTypeSpeed(self, threshold, statisticsFunc = median):
676 '''Classifies slow and fast road users
677 slow: non-motorized -> pedestrians
678 fast: motorized -> cars'''
679 if statisticsFunc(self.velocities.norm()) >= threshold:
680 self.setUserType(userType2Num['car'])
681 else:
682 self.setUserType(userType2Num['pedestrian'])
683
673 @staticmethod 684 @staticmethod
674 def collisionCourseDotProduct(movingObject1, movingObject2, instant): 685 def collisionCourseDotProduct(movingObject1, movingObject2, instant):
675 'A positive result indicates that the road users are getting closer' 686 'A positive result indicates that the road users are getting closer'
676 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) 687 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant)
677 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) 688 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant)