Mercurial > hg > nsaunier > traffic-intelligence
comparison python/moving.py @ 666:93633ce122c3
added function to count features in objects
| author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
|---|---|
| date | Wed, 20 May 2015 14:21:54 +0200 |
| parents | 15e244d2a1b5 |
| children | 5473b7460375 |
comparison
equal
deleted
inserted
replaced
| 665:15e244d2a1b5 | 666:93633ce122c3 |
|---|---|
| 1119 | 1119 |
| 1120 def getFeature(self, i): | 1120 def getFeature(self, i): |
| 1121 if self.hasFeatures() and i<len(self.features): | 1121 if self.hasFeatures() and i<len(self.features): |
| 1122 return self.features[i] | 1122 return self.features[i] |
| 1123 else: | 1123 else: |
| 1124 return None | |
| 1125 | |
| 1126 def getFeatureNumbers(self): | |
| 1127 '''Returns the number of features at each instant | |
| 1128 dict instant -> number of features''' | |
| 1129 if self.hasFeatures(): | |
| 1130 featureNumbers = {} | |
| 1131 for t in self.getTimeInterval(): | |
| 1132 n = 0 | |
| 1133 for f in self.getFeatures(): | |
| 1134 if f.existsAtInstant(t): | |
| 1135 n += 1 | |
| 1136 featureNumbers[t]=n | |
| 1137 return featureNumbers | |
| 1138 else: | |
| 1139 print('Object {} has no features loaded.'.format(self.getNum())) | |
| 1124 return None | 1140 return None |
| 1125 | 1141 |
| 1126 def getSpeeds(self): | 1142 def getSpeeds(self): |
| 1127 return self.getVelocities().norm() | 1143 return self.getVelocities().norm() |
| 1128 | 1144 |
