diff --git a/trajectorySmoothing/MovingAverageSmoother.py b/trajectorySmoothing/MovingAverageSmoother.py index b604ba78e2e83766b7596f288768ee71beea0e2e..9048e54f50cbc41fd216fbad6930bbb790146304 100644 --- a/trajectorySmoothing/MovingAverageSmoother.py +++ b/trajectorySmoothing/MovingAverageSmoother.py @@ -50,6 +50,42 @@ class MovingAverageSmoother(object): 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): def __init__(self, num_frames=30):