Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 524:1dced8932b08
corrected bugs
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Thu, 19 Jun 2014 13:31:00 -0400 |
| parents | ce4eaabacc26 |
| children | 21bdeb29f855 |
comparison
equal
deleted
inserted
replaced
| 523:ce4eaabacc26 | 524:1dced8932b08 |
|---|---|
| 819 return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) | 819 return predictPositionNoLimit(nTimeSteps, self.getPositionAtInstant(instant), self.getVelocityAtInstant(instant), externalAcceleration) |
| 820 | 820 |
| 821 ### | 821 ### |
| 822 # User Type Classification | 822 # User Type Classification |
| 823 ### | 823 ### |
| 824 def classifyUserTypeSpeedPedstrianCar(self, threshold, aggregationFunc = median, ignoreNInstantsAtEnds = 0): | 824 def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, ignoreNInstantsAtEnds = 0): |
| 825 '''Classifies slow and fast road users | 825 '''Classifies slow and fast road users |
| 826 slow: non-motorized -> pedestrians | 826 slow: non-motorized -> pedestrians |
| 827 fast: motorized -> cars''' | 827 fast: motorized -> cars''' |
| 828 if ignoreNInstantsAtEnds > 0: | 828 if ignoreNInstantsAtEnds > 0: |
| 829 speeds = self.getSpeeds()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds] | 829 speeds = self.getSpeeds()[ignoreNInstantsAtEnds:-ignoreNInstantsAtEnds] |
| 832 if aggregationFunc(speeds) >= threshold: | 832 if aggregationFunc(speeds) >= threshold: |
| 833 self.setUserType(userType2Num['car']) | 833 self.setUserType(userType2Num['car']) |
| 834 else: | 834 else: |
| 835 self.setUserType(userType2Num['pedestrian']) | 835 self.setUserType(userType2Num['pedestrian']) |
| 836 | 836 |
| 837 def classifyUserTypeSpeed(self, aggregationFunc = median, speedProbabilities): | 837 def classifyUserTypeSpeed(self, speedProbabilities, aggregationFunc = median): |
| 838 '''Classifies road user per road user type | 838 '''Classifies road user per road user type |
| 839 speedProbabilities are functions return P(speed|class) | 839 speedProbabilities are functions return P(speed|class) |
| 840 in a dictionary indexed by user type names | 840 in a dictionary indexed by user type names |
| 841 Returns probabilities for each class | 841 Returns probabilities for each class |
| 842 | 842 |
| 874 else: | 874 else: |
| 875 self.userTypes[instant] = userType2Num['car'] | 875 self.userTypes[instant] = userType2Num['car'] |
| 876 else: | 876 else: |
| 877 self.userTypes[instant] = userType2Num['unknown'] | 877 self.userTypes[instant] = userType2Num['unknown'] |
| 878 | 878 |
| 879 def classifyUserTypeHoGSVM(self, images, pedBikeCarSVM, homography, width, height, bikeCarSVM = None, pedBikeSpeedTreshold = float('Inf'), bikeCarSpeedThreshold = float('Inf'), aggregationFunc = median, speedProbabilities = None, px = 0.2, py = 0.2, pixelThreshold = 800): | 879 def classifyUserTypeHoGSVM(self, images, pedBikeCarSVM, homography, width, height, bikeCarSVM = None, pedBikeSpeedTreshold = float('Inf'), bikeCarSpeedThreshold = float('Inf'), speedProbabilities = None, aggregationFunc = median, px = 0.2, py = 0.2, pixelThreshold = 800): |
| 880 '''Agregates SVM detections in each image and returns probability | 880 '''Agregates SVM detections in each image and returns probability |
| 881 (proportion of instants with classification in each category) | 881 (proportion of instants with classification in each category) |
| 882 | 882 |
| 883 iamges is a dictionary of images indexed by instant | 883 iamges is a dictionary of images indexed by instant |
| 884 With default parameters, the general (ped-bike-car) classifier will be used | 884 With default parameters, the general (ped-bike-car) classifier will be used |
| 890 if len(self.userTypes) != self.length(): # if classification has not been done previously | 890 if len(self.userTypes) != self.length(): # if classification has not been done previously |
| 891 for t in self.getTimeInterval(): | 891 for t in self.getTimeInterval(): |
| 892 if t not in self.userTypes: | 892 if t not in self.userTypes: |
| 893 self.classifyUserTypeHoGSVMAtInstant(images[t], pedBikeCarSVM, t, homography, width, height, bikeCarSVM, pedBikeSpeedTreshold, bikeCarSpeedThreshold, px, py, pixelThreshold) | 893 self.classifyUserTypeHoGSVMAtInstant(images[t], pedBikeCarSVM, t, homography, width, height, bikeCarSVM, pedBikeSpeedTreshold, bikeCarSpeedThreshold, px, py, pixelThreshold) |
| 894 # compute P(Speed|Class) | 894 # compute P(Speed|Class) |
| 895 if speedProbabilities = None: # equiprobable information from speed | 895 if speedProbabilities == None: # equiprobable information from speed |
| 896 userTypeProbabilities = {userType2Num['car']: 1., userType2Num['pedestrian']: 1., userType2Num['bicycle']: 1.} | 896 userTypeProbabilities = {userType2Num['car']: 1., userType2Num['pedestrian']: 1., userType2Num['bicycle']: 1.} |
| 897 else: | 897 else: |
| 898 userTypeProbabilities = {userType2Num[userTypename]: speedProbabilities[userTypename](self.aggregatedSpeed) for userTypename in speedProbabilities} | 898 userTypeProbabilities = {userType2Num[userTypename]: speedProbabilities[userTypename](self.aggregatedSpeed) for userTypename in speedProbabilities} |
| 899 # result is P(Class|Appearance) x P(Speed|Class) | 899 # result is P(Class|Appearance) x P(Speed|Class) |
| 900 nInstantsUserType = {userType2Num[userTypename]: 0 for userTypename in userTypeProbabilities}# number of instants the object is classified as userTypename | 900 nInstantsUserType = {userType2Num[userTypename]: 0 for userTypename in userTypeProbabilities}# number of instants the object is classified as userTypename |
