# HG changeset patch # User Nicolas Saunier # Date 1400613535 14400 # Node ID c81cbd6953fb06a0cdb6bb8582ee2619ea97720d # Parent 3b99d712bbee243b5a9a90283ac5863b7a02ba4e update to classify speed to remove data at both ends diff -r 3b99d712bbee -r c81cbd6953fb python/cvutils.py --- a/python/cvutils.py Fri May 09 14:09:14 2014 -0400 +++ b/python/cvutils.py Tue May 20 15:18:55 2014 -0400 @@ -5,7 +5,7 @@ import cv2 opencvAvailable = True except ImportError: - print('OpenCV library could not be loaded (video replay functions will not be available)') + print('OpenCV library could not be loaded (video replay functions will not be available)') # TODO change to logging module opencvAvailable = False try: import skimage diff -r 3b99d712bbee -r c81cbd6953fb python/ml.py --- a/python/ml.py Fri May 09 14:09:14 2014 -0400 +++ b/python/ml.py Tue May 20 15:18:55 2014 -0400 @@ -24,8 +24,8 @@ def train(self, samples, responses): self.model.train(samples, responses, params = self.params) - def predict(self, sample): - return np.float32(self.model.predict(s)) + def predict(self, samples): + return np.float32([self.model.predict(s) for s in samples]) class Centroid: diff -r 3b99d712bbee -r c81cbd6953fb python/moving.py --- a/python/moving.py Fri May 09 14:09:14 2014 -0400 +++ b/python/moving.py Tue May 20 15:18:55 2014 -0400 @@ -805,11 +805,15 @@ at constant speed''' return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) - def classifyUserTypeSpeed(self, threshold, statisticsFunc = median): + def classifyUserTypeSpeed(self, threshold, statisticsFunc = median, ignoreNInstantsAtEnds = 0): '''Classifies slow and fast road users slow: non-motorized -> pedestrians fast: motorized -> cars''' - if statisticsFunc(self.velocities.norm()) >= threshold: + if ignoreNInstantsAtEnds > 0: + speeds = self.velocities.norm()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds] + else: + speeds = self.velocities.norm() + if statisticsFunc(speeds) >= threshold: self.setUserType(userType2Num['car']) else: self.setUserType(userType2Num['pedestrian'])