1. Nicolas Saunier
  2. TrafficIntelligence

Commits

Nicolas Saunier  committed fd9641c

added function to classify object at instant from SVM

  • Participants
  • Parent commits 4ad5123
  • Branches default

Comments (0)

Files changed (2)

File python/cvutils.py

View file
  • Ignore whitespace
         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
 
 

File python/moving.py

View file
  • Ignore whitespace
         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'