comparison python/moving.py @ 812:21f10332c72b

moved the classification parameters from tracking.cfg to a new classifier.cfg and made all classification parameters apparent
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 10 Jun 2016 17:07:36 -0400
parents 3aa6102ccc12
children 14e4ad7c7420
comparison
equal deleted inserted replaced
810:082a5c2685f4 812:21f10332c72b
1540 return userType2Num['car'] 1540 return userType2Num['car']
1541 self.appearanceClassifier = CarClassifier() 1541 self.appearanceClassifier = CarClassifier()
1542 1542
1543 self.userTypes = {} 1543 self.userTypes = {}
1544 1544
1545 def classifyUserTypeHoGSVMAtInstant(self, img, instant, homography, width, height, px = 0.2, py = 0.2, minNPixels = 800): 1545 def classifyUserTypeHoGSVMAtInstant(self, img, instant, homography, width, height, px, py, minNPixels, rescaleSize, orientations, pixelsPerCell, cellsPerBlock):
1546 '''Extract the image box around the object and 1546 '''Extracts the image box around the object
1547 applies the SVM model on it''' 1547 (of square size max(width, height) of the box around the features,
1548 with an added px or py for width and height (around the box))
1549 computes HOG on this cropped image (with parameters rescaleSize, orientations, pixelsPerCell, cellsPerBlock)
1550 and applies the SVM model on it'''
1548 croppedImg, yCropMin, yCropMax, xCropMin, xCropMax = cvutils.imageBox(img, self, instant, homography, width, height, px, py, minNPixels) 1551 croppedImg, yCropMin, yCropMax, xCropMin, xCropMax = cvutils.imageBox(img, self, instant, homography, width, height, px, py, minNPixels)
1549 if croppedImg is not None and len(croppedImg) > 0: 1552 if croppedImg is not None and len(croppedImg) > 0:
1550 hog = cvutils.HOG(croppedImg)#HOG(image, rescaleSize = (64, 64), orientations=9, pixelsPerCell=(8, 8), cellsPerBlock=(2, 2), visualize=False, normalize=False) 1553 hog = cvutils.HOG(croppedImg, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, visualize=False, normalize=False)
1551 self.userTypes[instant] = int(self.appearanceClassifier.predict(hog)) 1554 self.userTypes[instant] = int(self.appearanceClassifier.predict(hog))
1552 else: 1555 else:
1553 self.userTypes[instant] = userType2Num['unknown'] 1556 self.userTypes[instant] = userType2Num['unknown']
1554 1557
1555 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, nInstantsIgnoredAtEnds = 0, px = 0.2, py = 0.2, minNPixels = 800): 1558 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, nInstantsIgnoredAtEnds = 0, px = 0.2, py = 0.2, minNPixels = 800, rescaleSize = (64, 64), orientations = 9, pixelsPerCell = (8,8), cellsPerBlock = (2,2)):
1556 '''Agregates SVM detections in each image and returns probability 1559 '''Agregates SVM detections in each image and returns probability
1557 (proportion of instants with classification in each category) 1560 (proportion of instants with classification in each category)
1558 1561
1559 images is a dictionary of images indexed by instant 1562 images is a dictionary of images indexed by instant
1560 With default parameters, the general (ped-bike-car) classifier will be used 1563 With default parameters, the general (ped-bike-car) classifier will be used
1565 self.initClassifyUserTypeHoGSVM(aggregationFunc, pedBikeCarSVM, bikeCarSVM, pedBikeSpeedTreshold, bikeCarSpeedThreshold, nInstantsIgnoredAtEnds) 1568 self.initClassifyUserTypeHoGSVM(aggregationFunc, pedBikeCarSVM, bikeCarSVM, pedBikeSpeedTreshold, bikeCarSpeedThreshold, nInstantsIgnoredAtEnds)
1566 1569
1567 if len(self.userTypes) != self.length() and images is not None: # if classification has not been done previously 1570 if len(self.userTypes) != self.length() and images is not None: # if classification has not been done previously
1568 for t in self.getTimeInterval(): 1571 for t in self.getTimeInterval():
1569 if t not in self.userTypes: 1572 if t not in self.userTypes:
1570 self.classifyUserTypeHoGSVMAtInstant(images[t], t, homography, width, height, px, py, minNPixels) 1573 self.classifyUserTypeHoGSVMAtInstant(images[t], t, homography, width, height, px, py, minNPixels, rescaleSize, orientations, pixelsPerCell, cellsPerBlock)
1571 # compute P(Speed|Class) 1574 # compute P(Speed|Class)
1572 if speedProbabilities is None or self.aggregatedSpeed < minSpeedEquiprobable: # equiprobable information from speed 1575 if speedProbabilities is None or self.aggregatedSpeed < minSpeedEquiprobable: # equiprobable information from speed
1573 userTypeProbabilities = {userType2Num['car']: 1., userType2Num['pedestrian']: 1., userType2Num['bicycle']: 1.} 1576 userTypeProbabilities = {userType2Num['car']: 1., userType2Num['pedestrian']: 1., userType2Num['bicycle']: 1.}
1574 else: 1577 else:
1575 userTypeProbabilities = {userType2Num[userTypename]: speedProbabilities[userTypename](self.aggregatedSpeed) for userTypename in speedProbabilities} 1578 userTypeProbabilities = {userType2Num[userTypename]: speedProbabilities[userTypename](self.aggregatedSpeed) for userTypename in speedProbabilities}