Skip to content
Snippets Groups Projects
Commit 9376e2f3 authored by Janine's avatar Janine
Browse files

add function smooth_faster to MovingAverageSmoother.py

parent 9485db93
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,42 @@ class MovingAverageSmoother(object): ...@@ -50,6 +50,42 @@ class MovingAverageSmoother(object):
return Trajectory(trajectory.person_id, smooth_x, smooth_y, smooth_z, trajectory.frames, trajectory.framerate) return Trajectory(trajectory.person_id, smooth_x, smooth_y, smooth_z, trajectory.frames, trajectory.framerate)
# faster version of smooth function
def smooth_faster(self, trajectory, symmetric=True):
nf = int(self.num_frames / 2)
smooth_x = []
smooth_y = []
start = trajectory.startframe
end = start + 1
distance = end - start
summe = sum([trajectory[f] for f in range(start, end)])
smooth_x.append(summe[0] / distance)
smooth_y.append(summe[1] / distance)
for i in range(1, len(trajectory.frames)):
if trajectory.startframe >= trajectory.frames[i] - nf:
summe = sum([trajectory[f] for f in range(trajectory.startframe, trajectory.frames[i + i + 1])])
distance = trajectory.frames[i + i + 1] - trajectory.startframe
elif trajectory.endframe < trajectory.frames[i] + nf:
summe = sum([trajectory[f] for f in
range(trajectory.frames[i - (trajectory.endframe - i)], trajectory.endframe + 1)])
distance = trajectory.endframe + 1 - trajectory.frames[i - (trajectory.endframe - i)]
else:
summe[0] = summe[0] - (trajectory[trajectory.frames[i] - nf - 1])[0] + \
(trajectory[trajectory.frames[i] + nf])[0]
summe[1] = summe[1] - (trajectory[trajectory.frames[i] - nf - 1])[1] + \
(trajectory[trajectory.frames[i] + nf])[1]
smooth_x.append(summe[0] / distance)
smooth_y.append(summe[1] / distance)
smooth_z = trajectory.z_values
return Trajectory(trajectory.person_id, smooth_x, smooth_y, smooth_z, trajectory.frames, trajectory.framerate)
class VelocityAdaptiveMASmoother(object): class VelocityAdaptiveMASmoother(object):
def __init__(self, num_frames=30): def __init__(self, num_frames=30):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment