Mercurial Hosting > traffic-intelligence
comparison python/moving.py @ 562:259ccb3dd962
work on object trajectory smoothing
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 16 Jul 2014 02:12:34 -0400 |
parents | f13220f765e0 |
children | 072cedc3f33d |
comparison
equal
deleted
inserted
replaced
561:ee45c6eb6d49 | 562:259ccb3dd962 |
---|---|
874 | 874 |
875 def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)): | 875 def predictPosition(self, instant, nTimeSteps, externalAcceleration = Point(0,0)): |
876 '''Predicts the position of object at instant+deltaT, | 876 '''Predicts the position of object at instant+deltaT, |
877 at constant speed''' | 877 at constant speed''' |
878 return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) | 878 return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) |
879 | |
880 def computeSmoothTrajectory(self, minCommonIntervalLength): | |
881 '''Computes the trajectory as the mean of all features | |
882 if a feature exists, its position is | |
883 | |
884 TODO? not use the first/last 1-.. positions''' | |
885 from numpy import array, median | |
886 nFeatures = len(self.features) | |
887 if nFeatures == 0: | |
888 print('Empty object features\nCannot compute smooth trajectory') | |
889 else: | |
890 # compute the relative position vectors | |
891 relativePositions = {} # relativePositions[(i,j)] is the position of j relative to i | |
892 for i in xrange(nFeatures): | |
893 for j in xrange(i): | |
894 fi = self.features[i] | |
895 fj = self.features[j] | |
896 inter = fi.commonTimeInterval(fj) | |
897 if inter.length() >= minCommonIntervalLength: | |
898 xi = array(fi.getXCoordinates()[inter.first-fi.getFirstInstant():int(fi.length())-(fi.getLastInstant()-inter.last)]) | |
899 yi = array(fi.getYCoordinates()[inter.first-fi.getFirstInstant():int(fi.length())-(fi.getLastInstant()-inter.last)]) | |
900 xj = array(fj.getXCoordinates()[inter.first-fj.getFirstInstant():int(fj.length())-(fj.getLastInstant()-inter.last)]) | |
901 yj = array(fj.getYCoordinates()[inter.first-fj.getFirstInstant():int(fj.length())-(fj.getLastInstant()-inter.last)]) | |
902 relativePositions[(i,j)] = Point(median(xj-xi), median(yj-yi)) | |
903 relativePositions[(j,i)] = -relativePositions[(i,j)] | |
879 | 904 |
880 ### | 905 ### |
881 # User Type Classification | 906 # User Type Classification |
882 ### | 907 ### |
883 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, ignoreNInstantsAtEnds = 0): | 908 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, ignoreNInstantsAtEnds = 0): |