comparison python/moving.py @ 928:063d1267585d

work in progress
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 12 Jul 2017 01:24:31 -0400
parents 630934595871
children be28a3538dc9
comparison
equal deleted inserted replaced
927:c030f735c594 928:063d1267585d
549 def predictPosition(position, speedOrientation, control, maxSpeed = None): 549 def predictPosition(position, speedOrientation, control, maxSpeed = None):
550 '''Predicts the position (moving.Point) at the next time step with given control input (deltaSpeed, deltaTheta) 550 '''Predicts the position (moving.Point) at the next time step with given control input (deltaSpeed, deltaTheta)
551 speedOrientation is the other encoding of velocity, (speed, orientation) 551 speedOrientation is the other encoding of velocity, (speed, orientation)
552 speedOrientation and control are NormAngle''' 552 speedOrientation and control are NormAngle'''
553 predictedSpeedTheta = speedOrientation+control 553 predictedSpeedTheta = speedOrientation+control
554 if maxSpeed: 554 if maxSpeed is not None:
555 predictedSpeedTheta.norm = min(predictedSpeedTheta.norm, maxSpeed) 555 predictedSpeedTheta.norm = min(predictedSpeedTheta.norm, maxSpeed)
556 predictedPosition = position+predictedSpeedTheta.getPoint() 556 predictedPosition = position+predictedSpeedTheta.getPoint()
557 return predictedPosition, predictedSpeedTheta 557 return predictedPosition, predictedSpeedTheta
558 558
559 559
1559 for userTypename in speedProbabilities: 1559 for userTypename in speedProbabilities:
1560 userTypeProbabilities[userType2Num[userTypename]] = speedProbabilities[userTypename](self.aggregatedSpeed) 1560 userTypeProbabilities[userType2Num[userTypename]] = speedProbabilities[userTypename](self.aggregatedSpeed)
1561 self.setUserType(utils.argmaxDict(userTypeProbabilities)) 1561 self.setUserType(utils.argmaxDict(userTypeProbabilities))
1562 return userTypeProbabilities 1562 return userTypeProbabilities
1563 1563
1564 def initClassifyUserTypeHoGSVM(self, aggregationFunc, pedBikeCarSVM, bikeCarSVM = None, pedBikeSpeedTreshold = float('Inf'), bikeCarSpeedThreshold = float('Inf'), nInstantsIgnoredAtEnds = 0): 1564 def initClassifyUserTypeHoGSVM(self, aggregationFunc, pedBikeCarSVM, bikeCarSVM = None, pedBikeSpeedTreshold = float('Inf'), bikeCarSpeedThreshold = float('Inf'), nInstantsIgnoredAtEnds = 0, homography = None, intrinsicCameraMatrix = None, distortionCoefficients = None):
1565 '''Initializes the data structures for classification 1565 '''Initializes the data structures for classification
1566 1566
1567 TODO? compute speed for longest feature?''' 1567 TODO? compute speed for longest feature?'''
1568 self.aggregatedSpeed = aggregationFunc(self.getSpeeds(nInstantsIgnoredAtEnds)) 1568 self.aggregatedSpeed = aggregationFunc(self.getSpeeds(nInstantsIgnoredAtEnds))
1569 if self.aggregatedSpeed < pedBikeSpeedTreshold or bikeCarSVM is None: 1569 if self.aggregatedSpeed < pedBikeSpeedTreshold or bikeCarSVM is None:
1573 else: 1573 else:
1574 class CarClassifier: 1574 class CarClassifier:
1575 def predict(self, hog): 1575 def predict(self, hog):
1576 return userType2Num['car'] 1576 return userType2Num['car']
1577 self.appearanceClassifier = CarClassifier() 1577 self.appearanceClassifier = CarClassifier()
1578 1578 # project feature positions
1579 if self.hasFeatures():
1580 for f in self.getFeatures():
1581 f.projectedPositions = cvutils.projectArray(homography, f.getPositions().asArray(), intrinsicCameraMatrix, distortionCoefficients)
1579 self.userTypes = {} 1582 self.userTypes = {}
1580 1583
1581 def classifyUserTypeHoGSVMAtInstant(self, img, instant, homography, width, height, px, py, minNPixels, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm): 1584 def classifyUserTypeHoGSVMAtInstant(self, img, instant, homography, width, height, px, py, minNPixels, rescaleSize, orientations, pixelsPerCell, cellsPerBlock, blockNorm):
1582 '''Extracts the image box around the object 1585 '''Extracts the image box around the object
1583 (of square size max(width, height) of the box around the features, 1586 (of square size max(width, height) of the box around the features,