changeset 683:f3a0b652b590 dev

added function to display the speed distributions and optimize a little going through objects
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 05 Jun 2015 11:04:06 +0200
parents fbe29be25501
children 6d2ece4aed7c
files Makefile scripts/classify-objects.py scripts/uninstall-scripts.sh
diffstat 3 files changed, 36 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Fri Jun 05 02:35:29 2015 +0200
+++ b/Makefile	Fri Jun 05 11:04:06 2015 +0200
@@ -1,3 +1,4 @@
+INSTALL_DIR = /usr/local/bin
 
 cexe:
 	@cd c && make feature-based-tracking
@@ -17,9 +18,9 @@
 	@cp bin/feature-based-tracking /usr/local/bin
 	@echo "========================================="
 	@echo "Copying Python scripts"
-	@cp scripts/* /usr/local/bin
+	@cp scripts/* $(INSTALL_DIR)
 
 uninstall:
 	@echo "Uninstalling for Linux"
-	rm /usr/local/bin/feature-based-tracking 
-	@cd scripts && ./uninstall-scripts.sh
\ No newline at end of file
+	rm $(INSTALL_DIR)/feature-based-tracking 
+	@cd scripts && ./uninstall-scripts.sh $(INSTALL_DIR)
--- a/scripts/classify-objects.py	Fri Jun 05 02:35:29 2015 +0200
+++ b/scripts/classify-objects.py	Fri Jun 05 11:04:06 2015 +0200
@@ -12,6 +12,8 @@
 
 parser = argparse.ArgumentParser(description='The program processes indicators for all pairs of road users in the scene')
 parser.add_argument('--cfg', dest = 'configFilename', help = 'name of the configuration file', required = True)
+parser.add_argument('--plot-speed-distributions', dest = 'plotSpeedDistribution', help = 'simply plots the distributions used for each user type', action = 'store_true')
+parser.add_argument('--max-speed-distribution-plot', dest = 'maxSpeedDistributionPlot', help = 'if plotting the user distributions, the maximum speed to display', type = float, default = 50.)
 #parser.add_argument('-u', dest = 'undistort', help = 'undistort the video (because features have been extracted that way)', action = 'store_true')
 #parser.add_argument('-f', dest = 'firstFrameNum', help = 'number of first frame number to display', type = int)
 #parser.add_argument('--last-frame', dest = 'lastFrameNum', help = 'number of last frame number to save (for image saving, no display is made)', type = int)
@@ -23,7 +25,8 @@
 params = storage.ProcessParameters(args.configFilename)
 
 params.convertToFrames(3.6)
-invHomography = np.linalg.inv(params.homography)
+if params.homography is not None:
+    invHomography = np.linalg.inv(params.homography)
 
 if params.speedAggregationMethod == 'median':
     speedAggregationFunc = np.median
@@ -33,8 +36,7 @@
     speedAggregationFunc = lambda speeds: np.percentile(speeds, args.speedAggregationQuantile)
 else:
     print('Unknown speed aggregation method: {}. Exiting'.format(params.speedAggregationMethod))
-    from sys import exit
-    exit()
+    sys.exit()
 
 pedBikeCarSVM = ml.SVM()
 pedBikeCarSVM.load(params.pedBikeCarSVMFilename)
@@ -46,9 +48,17 @@
                       'pedestrian': lambda s: norm(params.meanPedestrianSpeed, params.stdPedestrianSpeed).pdf(s), 
                       'bicycle': lambda s: lognorm(params.scaleCyclistSpeed, loc = 0., scale = np.exp(params.locationCyclistSpeed)).pdf(s)} # lognorm shape, loc, scale
 
-def plotSpeedProbabilities():
+if args.plotSpeedDistribution:
+    import matplotlib.pyplot as plt
+    plt.figure()
     for k in speedProbabilities:
-        plot(arange(0.1, 50, 0.1), [speedProbabilities[k](s/3.6/25) for s in arange(0.1, 50, 0.1)])
+        plt.plot(np.arange(0.1, args.maxSpeedDistributionPlot, 0.1), [speedProbabilities[k](s/3.6/25) for s in np.arange(0.1, args.maxSpeedDistributionPlot, 0.1)], label = k)
+    plt.xlabel('Speed (km/h)')
+    plt.ylabel('Probability')
+    plt.legend()
+    plt.title('Probability Density Function')
+    plt.show()
+    sys.exit()
 
 objects = storage.loadTrajectoriesFromSqlite(params.databaseFilename, 'object')
 features = storage.loadTrajectoriesFromSqlite(params.databaseFilename, 'feature')
@@ -75,12 +85,18 @@
         if ret:
             if frameNum%50 == 0:
                 print('frame number: {}'.format(frameNum))
+                currentObjects = []
+                for obj in objects:
+                    if obj.getLastFrameNum() < frameNum:
+                        obj.classifyUserTypeHoGSVM(minSpeedEquiprobable = params.minSpeedEquiprobable, speedProbabilities = speedProbabilities)
+                    else:
+                        currentObjects.append(obj)
+                objects = currentObjects
             if params.undistort:
                 img = cv2.remap(img, map1, map2, interpolation=cv2.INTER_LINEAR)
             for obj in objects:
                 if obj.existsAtInstant(frameNum):
                     if obj.getFirstInstant() == frameNum:
-                        print 'first frame for obj {}'.format(obj.getNum())
                         obj.initClassifyUserTypeHoGSVM(speedAggregationFunc, pedBikeCarSVM, bikeCarSVM, params.maxPedestrianSpeed, params.maxCyclistSpeed, params.nFramesIgnoreAtEnds)
                     obj.classifyUserTypeHoGSVMAtInstant(img, frameNum, invHomography, width, height, 0.2, 0.2, 800) # px, py, pixelThreshold
         frameNum += 1
--- a/scripts/uninstall-scripts.sh	Fri Jun 05 02:35:29 2015 +0200
+++ b/scripts/uninstall-scripts.sh	Fri Jun 05 11:04:06 2015 +0200
@@ -1,7 +1,15 @@
 #!/bin/sh
-installDirname='/usr/local/bin'
+if [ $# -ge 1 ];
+then
+    installDirname=$1
+    echo 'Removing from directory '$installDirname
+else
+    installDirname='/usr/local/bin'
+    echo 'Removing from default directory '$installDirname
+fi
+
 for filename in *
 do
     echo 'rm '$installDirname/$filename
     rm $installDirname/$filename
-done
\ No newline at end of file
+done