diff python/moving.py @ 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 47d9970ee954
children ce40a89bd6ae
line wrap: on
line diff
--- 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'