nsaunier/traffic-intelligence
added smoothing functions and velocity generation to dltrack
Commit 20a5e1292321 · Nicolas Saunier · 2024-06-10 16:44 -0400
Comments
No comments yet.
Diff
diff --git a/scripts/dltrack.py b/scripts/dltrack.py
--- a/scripts/dltrack.py
+++ b/scripts/dltrack.py
@@ -256,7 +256,8 @@
if smoothingHalfWidth is not None: # smoothing
for num, obj in objects.items():
for f in obj.getFeatures():
- f.positions = f.getPositions().filterMovingWindow(smoothingHalfWidth)
+ f.smoothPositions(smoothingHalfWidth, replace = True)#f.positions = f.getPositions().filterMovingWindow(smoothingHalfWidth)
+ f.computeVelocities()
storage.saveTrajectoriesToSqlite(args.databaseFilename, list(objects.values()), 'object')
diff --git a/trafficintelligence/moving.py b/trafficintelligence/moving.py
--- a/trafficintelligence/moving.py
+++ b/trafficintelligence/moving.py
@@ -1747,6 +1747,30 @@
else:
return speeds
+ def computeVelocities(self, halfWidth = None):
+ '''compute velocities, smoothed if halfwidth is not None '''
+ if halfWidth is None:
+ self.velocities = self.getPositions().differentiate(True)
+ else:
+ self.velocities = self.getPositions().differentiate().filterMovingWindow(halfWidth)
+ self.velocities.addPosition(self.velocities[-1])
+
+ def smoothPositions(self, halfWidth, replace = False):
+ 'Returns the smoothed positions (or replaces them)'
+ smoothed = self.getPositions().filterMovingWindow(halfWidth)
+ if replace:
+ self.positions = smoothed
+ else:
+ return smoothed
+
+ def smoothVelocities(self, halfWidth, replace = False):
+ 'Returns the smoothed velocities (or replaces them)'
+ smoothed = self.getVelocities().filterMovingWindow(halfWidth)
+ if replace:
+ self.velocities = smoothed
+ else:
+ return smoothed
+
def getAccelerations(self, fromSpeeds = True, nInstantsIgnoredAtEnds = 0):
'''Returns the scalar acceleration by differentiating the speeds (fromSpeeds = True) or by differentiating the velocity (vector) and taking the norm (frompSpeeds = False. In the second case, speed is always positive'''
if fromSpeeds: