comparison python/moving.py @ 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 196a1fd498ba
children 184f1dd307f9
comparison
equal deleted inserted replaced
958:747a5c68bd3c 959:4f32d82ca390
1106 'bus', 1106 'bus',
1107 'truck'] 1107 'truck']
1108 1108
1109 userType2Num = utils.inverseEnumeration(userTypeNames) 1109 userType2Num = utils.inverseEnumeration(userTypeNames)
1110 1110
1111 class CarClassifier:
1112 def predict(self, hog):
1113 return userType2Num['car']
1114 carClassifier = CarClassifier()
1115
1111 class MovingObject(STObject, VideoFilenameAddable): 1116 class MovingObject(STObject, VideoFilenameAddable):
1112 '''Class for moving objects: a spatio-temporal object 1117 '''Class for moving objects: a spatio-temporal object
1113 with a trajectory and a geometry (constant volume over time) 1118 with a trajectory and a geometry (constant volume over time)
1114 and a usertype (e.g. road user) coded as a number (see userTypeNames) 1119 and a usertype (e.g. road user) coded as a number (see userTypeNames)
1115 ''' 1120 '''
1613 if self.aggregatedSpeed < pedBikeSpeedTreshold or bikeCarSVM is None: 1618 if self.aggregatedSpeed < pedBikeSpeedTreshold or bikeCarSVM is None:
1614 self.appearanceClassifier = pedBikeCarSVM 1619 self.appearanceClassifier = pedBikeCarSVM
1615 elif self.aggregatedSpeed < bikeCarSpeedThreshold: 1620 elif self.aggregatedSpeed < bikeCarSpeedThreshold:
1616 self.appearanceClassifier = bikeCarSVM 1621 self.appearanceClassifier = bikeCarSVM
1617 else: 1622 else:
1618 class CarClassifier: 1623 self.appearanceClassifier = carClassifier
1619 def predict(self, hog):
1620 return userType2Num['car']
1621 self.appearanceClassifier = CarClassifier()
1622 # project feature positions 1624 # project feature positions
1623 if self.hasFeatures(): 1625 if self.hasFeatures():
1624 for f in self.getFeatures(): 1626 for f in self.getFeatures():
1625 pp = cvutils.worldToImageProject(f.getPositions().asArray(), intrinsicCameraMatrix, distortionCoefficients, homography).tolist() 1627 pp = cvutils.worldToImageProject(f.getPositions().asArray(), intrinsicCameraMatrix, distortionCoefficients, homography).tolist()
1626 f.positions = Trajectory(pp) 1628 f.positions = Trajectory(pp)
1632 with an added px or py for width and height (around the box)) 1634 with an added px or py for width and height (around the box))
1633 computes HOG on this cropped image (with parameters rescaleSize, orientations, pixelsPerCell, cellsPerBlock) 1635 computes HOG on this cropped image (with parameters rescaleSize, orientations, pixelsPerCell, cellsPerBlock)
1634 and applies the SVM model on it''' 1636 and applies the SVM model on it'''
1635 croppedImg = cvutils.imageBox(img, self, instant, width, height, px, py, minNPixels) 1637 croppedImg = cvutils.imageBox(img, self, instant, width, height, px, py, minNPixels)
1636 if croppedImg is not None and len(croppedImg) > 0: 1638 if croppedImg is not None and len(croppedImg) > 0:
1637 hog = cvutils.HOG(croppedImg, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm, visualize=False, normalize=False) 1639 hog = cvutils.HOG(croppedImg, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm)
1638 self.userTypes[instant] = int(self.appearanceClassifier.predict(hog)) 1640 self.userTypes[instant] = int(self.appearanceClassifier.predict(hog))
1639 else: 1641 else:
1640 self.userTypes[instant] = userType2Num['unknown'] 1642 self.userTypes[instant] = userType2Num['unknown']
1641 1643
1642 def classifyUserTypeHoGSVM(self, pedBikeCarSVM = None, width = 0, height = 0, homography = None, images = None, bikeCarSVM = None, pedBikeSpeedTreshold = float('Inf'), bikeCarSpeedThreshold = float('Inf'), minSpeedEquiprobable = -1, speedProbabilities = None, aggregationFunc = median, maxPercentUnknown = 0.5, nInstantsIgnoredAtEnds = 0, px = 0.2, py = 0.2, minNPixels = 800, rescaleSize = (64, 64), orientations = 9, pixelsPerCell = (8,8), cellsPerBlock = (2,2)): 1644 def classifyUserTypeHoGSVM(self, pedBikeCarSVM = None, width = 0, height = 0, homography = None, images = None, bikeCarSVM = None, pedBikeSpeedTreshold = float('Inf'), bikeCarSpeedThreshold = float('Inf'), minSpeedEquiprobable = -1, speedProbabilities = None, aggregationFunc = median, maxPercentUnknown = 0.5, nInstantsIgnoredAtEnds = 0, px = 0.2, py = 0.2, minNPixels = 800, rescaleSize = (64, 64), orientations = 9, pixelsPerCell = (8,8), cellsPerBlock = (2,2)):