changeset 959:4f32d82ca390

corrected error due to change in Hog (scikit image)
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 24 Aug 2017 17:22:24 -0400
parents 747a5c68bd3c
children 0c1d1eeef544
files python/cvutils.py python/moving.py python/tests/moving.txt
diffstat 3 files changed, 22 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/python/cvutils.py	Fri Aug 18 18:00:11 2017 -0400
+++ b/python/cvutils.py	Thu Aug 24 17:22:24 2017 -0400
@@ -605,10 +605,10 @@
     from skimage.feature import hog
     from skimage import color, transform
     
-    def HOG(image, rescaleSize = (64, 64), orientations=9, pixelsPerCell=(8,8), cellsPerBlock=(2,2), blockNorm='L1', visualize=False, normalize=False):
+    def HOG(image, rescaleSize = (64, 64), orientations = 9, pixelsPerCell = (8,8), cellsPerBlock = (2,2), blockNorm = 'L1', visualize = False, transformSqrt = False):
         bwImg = color.rgb2gray(image)
         inputImg = transform.resize(bwImg, rescaleSize)
-        features = hog(inputImg, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize, normalize, True)
+        features = hog(inputImg, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize, transformSqrt, True)
         if visualize:
             from matplotlib.pyplot import imshow, figure, subplot
             hogViz = features[1]
@@ -620,11 +620,11 @@
             imshow(hogViz)
         return float32(features)
 
-    def createHOGTrainingSet(imageDirectory, classLabel, rescaleSize = (64,64), orientations=9, pixelsPerCell=(8,8), blockNorm='L1', cellsPerBlock=(2, 2), visualize=False, normalize=False):
+    def createHOGTrainingSet(imageDirectory, classLabel, rescaleSize = (64,64), orientations = 9, pixelsPerCell = (8,8), blockNorm = 'L1', cellsPerBlock = (2, 2), visualize = False, transformSqrt = False):
         inputData = []
         for filename in listdir(imageDirectory):
             img = imread(imageDirectory+filename)
-            features = HOG(img, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize, normalize)
+            features = HOG(img, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize, transformSqrt)
             inputData.append(features)
 
         nImages = len(inputData)
--- a/python/moving.py	Fri Aug 18 18:00:11 2017 -0400
+++ b/python/moving.py	Thu Aug 24 17:22:24 2017 -0400
@@ -1108,6 +1108,11 @@
 
 userType2Num = utils.inverseEnumeration(userTypeNames)
 
+class CarClassifier:
+    def predict(self, hog):
+        return userType2Num['car']
+carClassifier = CarClassifier()
+    
 class MovingObject(STObject, VideoFilenameAddable):
     '''Class for moving objects: a spatio-temporal object 
     with a trajectory and a geometry (constant volume over time) 
@@ -1615,10 +1620,7 @@
         elif self.aggregatedSpeed < bikeCarSpeedThreshold:
             self.appearanceClassifier = bikeCarSVM
         else:
-            class CarClassifier:
-                def predict(self, hog):
-                    return userType2Num['car']
-            self.appearanceClassifier = CarClassifier()
+            self.appearanceClassifier = carClassifier
         # project feature positions
         if self.hasFeatures():
             for f in self.getFeatures():
@@ -1634,7 +1636,7 @@
         and applies the SVM model on it'''
         croppedImg = cvutils.imageBox(img, self, instant, width, height, px, py, minNPixels)
         if croppedImg is not None and len(croppedImg) > 0:
-            hog = cvutils.HOG(croppedImg, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize=False, normalize=False)
+            hog = cvutils.HOG(croppedImg, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm)
             self.userTypes[instant] = int(self.appearanceClassifier.predict(hog))
         else:
             self.userTypes[instant] = userType2Num['unknown']
--- a/python/tests/moving.txt	Fri Aug 18 18:00:11 2017 -0400
+++ b/python/tests/moving.txt	Thu Aug 24 17:22:24 2017 -0400
@@ -203,13 +203,13 @@
 >>> gt1 = BBMovingObject(1, TimeInterval(0,10), MovingObject.generate(1, Point(0.2,0.6), Point(1.,0.), TimeInterval(0,10)), MovingObject.generate(2, Point(-0.2,-0.4), Point(1.,0.), TimeInterval(0,10)))
 >>> gt1.computeCentroidTrajectory()
 >>> computeClearMOT([gt1], [], 0.2, 0, 10)
-(None, 0.0, 11, 0, 0, 11)
+(None, 0.0, 11, 0, 0, 11, None, None)
 >>> computeClearMOT([], [o1], 0.2, 0, 10)
-(None, None, 0, 0, 11, 0)
+(None, None, 0, 0, 11, 0, None, None)
 >>> computeClearMOT([gt1], [o1], 0.2, 0, 10) # doctest:+ELLIPSIS
-(0.0999..., 1.0, 0, 0, 0, 11)
+(0.0999..., 1.0, 0, 0, 0, 11, None, None)
 >>> computeClearMOT([gt1], [o1], 0.05, 0, 10)
-(None, -1.0, 11, 0, 11, 11)
+(None, -1.0, 11, 0, 11, 11, None, None)
 
 >>> o1 = MovingObject(1, TimeInterval(0,3), positions = Trajectory([range(4), [0.1, 0.1, 1.1, 1.1]]))
 >>> o2 = MovingObject(2, TimeInterval(0,3), positions = Trajectory([range(4), [0.9, 0.9, -0.1, -0.1]]))
@@ -218,16 +218,16 @@
 >>> gt2 = BBMovingObject(2, TimeInterval(0,3), MovingObject(positions = Trajectory([range(4), [1.]*4])), MovingObject(positions = Trajectory([range(4), [1.]*4])))
 >>> gt2.computeCentroidTrajectory()
 >>> computeClearMOT([gt1, gt2], [o1, o2], 0.2, 0, 3) # doctest:+ELLIPSIS
-(0.1..., 0.75, 0, 2, 0, 8)
+(0.1..., 0.75, 0, 2, 0, 8, None, None)
 >>> computeClearMOT([gt2, gt1], [o2, o1], 0.2, 0, 3) # doctest:+ELLIPSIS
-(0.1..., 0.75, 0, 2, 0, 8)
+(0.1..., 0.75, 0, 2, 0, 8, None, None)
 >>> computeClearMOT([gt1], [o1, o2], 0.2, 0, 3)
-(0.1, -0.25, 0, 1, 4, 4)
+(0.1, -0.25, 0, 1, 4, 4, None, None)
 >>> computeClearMOT([gt1], [o2, o1], 0.2, 0, 3) # symmetry
-(0.1, -0.25, 0, 1, 4, 4)
+(0.1, -0.25, 0, 1, 4, 4, None, None)
 >>> computeClearMOT([gt1, gt2], [o1], 0.2, 0, 3) # doctest:+ELLIPSIS
-(0.100..., 0.375, 4, 1, 0, 8)
+(0.100..., 0.375, 4, 1, 0, 8, None, None)
 >>> computeClearMOT([gt2, gt1], [o1], 0.2, 0, 3) # doctest:+ELLIPSIS
-(0.100..., 0.375, 4, 1, 0, 8)
+(0.100..., 0.375, 4, 1, 0, 8, None, None)
 >>> computeClearMOT([gt1, gt2], [o1, o2], 0.08, 0, 3)
-(None, -1.0, 8, 0, 8, 8)
+(None, -1.0, 8, 0, 8, 8, None, None)