changeset 524:1dced8932b08

corrected bugs
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 19 Jun 2014 13:31:00 -0400
parents ce4eaabacc26
children 7124c7d2a663
files python/moving.py python/storage.py python/tests/moving.txt
diffstat 3 files changed, 24 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/python/moving.py	Wed Jun 18 23:40:47 2014 -0400
+++ b/python/moving.py	Thu Jun 19 13:31:00 2014 -0400
@@ -821,7 +821,7 @@
     ###
     # User Type Classification
     ###
-    def classifyUserTypeSpeedPedstrianCar(self, threshold, aggregationFunc = median, ignoreNInstantsAtEnds = 0):
+    def classifyUserTypeSpeedMotorized(self, threshold, aggregationFunc = median, ignoreNInstantsAtEnds = 0):
         '''Classifies slow and fast road users
         slow: non-motorized -> pedestrians
         fast: motorized -> cars'''
@@ -834,7 +834,7 @@
         else:
             self.setUserType(userType2Num['pedestrian'])
 
-    def classifyUserTypeSpeed(self, aggregationFunc = median, speedProbabilities):
+    def classifyUserTypeSpeed(self, speedProbabilities, aggregationFunc = median):
         '''Classifies road user per road user type
         speedProbabilities are functions return P(speed|class)
         in a dictionary indexed by user type names
@@ -876,7 +876,7 @@
         else:
             self.userTypes[instant] = userType2Num['unknown']
 
-    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):
+    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):
         '''Agregates SVM detections in each image and returns probability
         (proportion of instants with classification in each category)
 
@@ -892,7 +892,7 @@
                 if t not in self.userTypes:
                     self.classifyUserTypeHoGSVMAtInstant(images[t], pedBikeCarSVM, t, homography, width, height, bikeCarSVM, pedBikeSpeedTreshold, bikeCarSpeedThreshold, px, py, pixelThreshold)
         # compute P(Speed|Class)
-        if speedProbabilities = None: # equiprobable information from speed
+        if speedProbabilities == None: # equiprobable information from speed
             userTypeProbabilities = {userType2Num['car']: 1., userType2Num['pedestrian']: 1., userType2Num['bicycle']: 1.}
         else:
             userTypeProbabilities = {userType2Num[userTypename]: speedProbabilities[userTypename](self.aggregatedSpeed) for userTypename in speedProbabilities}
--- a/python/storage.py	Wed Jun 18 23:40:47 2014 -0400
+++ b/python/storage.py	Thu Jun 19 13:31:00 2014 -0400
@@ -419,13 +419,25 @@
             finally: self.sechead = None
         else: return self.fp.readline()
 
+def loadTrajectoriesFromVissimFile(filename, nObjects = -1, sequenceNum = -1):
+    '''Reads data from VISSIM .fzp trajectory file'''
+    objects = []
+
+    infile = openCheck(filename)
+    if not infile:
+        import sys
+        sys.exit()
+
+    
+    return objects
+    
 def loadTrajectoriesFromNgsimFile(filename, nObjects = -1, sequenceNum = -1):
     '''Reads data from the trajectory data provided by NGSIM project 
     and returns the list of Feature objects'''
     objects = []
 
-    input = openCheck(filename)
-    if not input:
+    infile = openCheck(filename)
+    if not infile:
         import sys
         sys.exit()
 
@@ -451,11 +463,11 @@
         obj.size = [float(numbers[8]), float(numbers[9])] # 8 lengh, 9 width # TODO: temporary, should use a geometry object
         return obj
 
-    numbers = input.readline().strip().split()
+    numbers = infile.readline().strip().split()
     if (len(numbers) > 0):
         obj = createObject(numbers)
 
-    for line in input:
+    for line in infile:
         numbers = line.strip().split()
         if obj.getNum() != int(numbers[0]):
             # check and adapt the length to deal with issues in NGSIM data
@@ -482,7 +494,7 @@
             if (obj.size[1] != float(numbers[9])):
                 print 'changed width obj %d' % (obj.getNum())
     
-    input.close()
+    infile.close()
     return objects
 
 def convertNgsimFile(inFile, outFile, append = False, nObjects = -1, sequenceNum = 0):
--- a/python/tests/moving.txt	Wed Jun 18 23:40:47 2014 -0400
+++ b/python/tests/moving.txt	Thu Jun 19 13:31:00 2014 -0400
@@ -95,12 +95,12 @@
 True
 
 >>> o1 = MovingObject(positions = Trajectory([[0]*3,[2]*3]), velocities = Trajectory([[0]*3,[1]*3]))
->>> o1.classifyUserTypeSpeed(0.5, np.median)
+>>> o1.classifyUserTypeSpeedMotorized(0.5, np.median)
 >>> userTypeNames[o1.getUserType()]
 'car'
->>> o1.classifyUserTypeSpeed(0.5, np.mean)
+>>> o1.classifyUserTypeSpeedMotorized(0.5, np.mean)
 >>> userTypeNames[o1.getUserType()]
 'car'
->>> o1.classifyUserTypeSpeed(1.5, np.median)
+>>> o1.classifyUserTypeSpeedMotorized(1.5, np.median)
 >>> userTypeNames[o1.getUserType()]
 'pedestrian'