Skip to content

Commit 3e20ea8

Browse files
author
arch
committed
improve avg function
1 parent be766ab commit 3e20ea8

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

funscript_editor/algorithms/opticalflow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ def tracking(self) -> str:
225225

226226
signal = Signal(self.video_info.fps)
227227
points = signal.get_local_min_max_points(result)
228+
# points = signal.get_direction_changes(result, filter_len=4)
228229
categorized_points = signal.categorize_points(result, points)
229230

230231
for k in self.funscripts:

funscript_editor/algorithms/signal.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from numpy.linalg import norm
1010
from funscript_editor.utils.config import HYPERPARAMETER
1111

12+
import matplotlib.pyplot as plt
1213

1314
@dataclass
1415
class SignalParameter:
@@ -63,10 +64,7 @@ def moving_average(x: list, w: int) -> list:
6364
if w == 1:
6465
return x
6566

66-
avg = np.convolve(x, np.ones(int(w*2)), 'valid') / int(w*2)
67-
return [avg[0] for _ in range(int(w))] \
68-
+ list(avg) \
69-
+ [avg[-1] for _ in range(len(avg)+w,len(x))]
67+
return np.convolve(x, np.ones(int(w*2)) / (w*2), 'same')
7068

7169

7270
@staticmethod

0 commit comments

Comments
 (0)