Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 519:4ad5123d969e | 520:fd9641cbd24b |
|---|---|
| 829 if statisticsFunc(speeds) >= threshold: | 829 if statisticsFunc(speeds) >= threshold: |
| 830 self.setUserType(userType2Num['car']) | 830 self.setUserType(userType2Num['car']) |
| 831 else: | 831 else: |
| 832 self.setUserType(userType2Num['pedestrian']) | 832 self.setUserType(userType2Num['pedestrian']) |
| 833 | 833 |
| 834 def classifyUserTypeHoGSVMAtInstant(self, img, svm, instant, homography, width, height, px = 0.2, py = 0.2, pixelThreshold = 800): | |
| 835 '''Extract the image box around the object and | |
| 836 applies the SVM model on it''' | |
| 837 from numpy import array | |
| 838 croppedImg, yCropMin, yCropMax, xCropMin, xCropMax = imageBox(img, self, instant, homography, width, height, px, py, pixelThreshold) | |
| 839 if len(croppedImg) > 0: # != [] | |
| 840 hog = array([cvutils.HOG(croppedImg)], dtype = np.float32) | |
| 841 return int(svm.predict(hog)) | |
| 842 else: | |
| 843 return userType2Num['unknown'] | |
| 844 | |
| 834 @staticmethod | 845 @staticmethod |
| 835 def collisionCourseDotProduct(movingObject1, movingObject2, instant): | 846 def collisionCourseDotProduct(movingObject1, movingObject2, instant): |
| 836 'A positive result indicates that the road users are getting closer' | 847 'A positive result indicates that the road users are getting closer' |
| 837 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) | 848 deltap = movingObject1.getPositionAtInstant(instant)-movingObject2.getPositionAtInstant(instant) |
| 838 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) | 849 deltav = movingObject2.getVelocityAtInstant(instant)-movingObject1.getVelocityAtInstant(instant) |
