changeset 520:fd9641cbd24b

added function to classify object at instant from SVM
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 18 Jun 2014 01:19:18 -0400
parents 4ad5123d969e
children 3707eeb20f25
files python/cvutils.py python/moving.py
diffstat 2 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/python/cvutils.py	Wed Jun 18 00:53:39 2014 -0400
+++ b/python/cvutils.py	Wed Jun 18 01:19:18 2014 -0400
@@ -205,9 +205,9 @@
         xCropMin = int(max(0, .5 * (xmin + xmax - a)))
         xCropMax = int(min(width - 1, .5 * (xmin + xmax + a)))
         if yCropMax != yCropMin and xCropMax != xCropMin and (yCropMax - yCropMin) * (xCropMax - xCropMin) > pixelThreshold:
-            imgcrop = img[yCropMin : yCropMax, xCropMin : xCropMax]
+            croppedImg = img[yCropMin : yCropMax, xCropMin : xCropMax]
         else:
-            imgcrop = []
+            croppedImg = []
         return imgcrop, yCropMin, yCropMax, xCropMin, xCropMax
 
 
--- a/python/moving.py	Wed Jun 18 00:53:39 2014 -0400
+++ b/python/moving.py	Wed Jun 18 01:19:18 2014 -0400
@@ -831,6 +831,17 @@
         else:
             self.setUserType(userType2Num['pedestrian'])
 
+    def classifyUserTypeHoGSVMAtInstant(self, img, svm, instant, homography, width, height, px = 0.2, py = 0.2, pixelThreshold = 800):
+        '''Extract the image box around the object and 
+        applies the SVM model on it'''
+        from numpy import array
+        croppedImg, yCropMin, yCropMax, xCropMin, xCropMax = imageBox(img, self, instant, homography, width, height, px, py, pixelThreshold)
+        if len(croppedImg) > 0: # != []
+            hog = array([cvutils.HOG(croppedImg)], dtype = np.float32)
+            return int(svm.predict(hog))
+        else:
+            return userType2Num['unknown']
+
     @staticmethod
     def collisionCourseDotProduct(movingObject1, movingObject2, instant):
         'A positive result indicates that the road users are getting closer'