Skip to content

Commit 7d03e9b

Browse files
author
arch
committed
predict point postition
1 parent d779553 commit 7d03e9b

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

funscript_editor/algorithms/opticalflow.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def update(self, frame_roi):
100100
self.trajectories = new_trajectories
101101

102102

103-
if self.frame_idx % self.feature_detect_interval == 0:
103+
if len(self.trajectories) == 0 or self.frame_idx % self.feature_detect_interval == 0:
104104
mask = np.zeros_like(frame_gray)
105105
mask[:] = 255
106106
p = cv2.goodFeaturesToTrack(frame_gray, mask = mask, **self.feature_params)
@@ -225,15 +225,20 @@ def tracking(self) -> str:
225225

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

229-
val = 0
230230
for k in self.funscripts:
231-
for p in points:
231+
for bottom_point in categorized_points['max']:
232232
self.funscripts[k].add_action(
233-
val,
234-
FFmpegStream.frame_to_millisec(self.get_absolute_framenumber(p * (1+self.params.skip_frames)), self.video_info.fps)
233+
0,
234+
FFmpegStream.frame_to_millisec(self.get_absolute_framenumber(bottom_point * (1+self.params.skip_frames)), self.video_info.fps)
235+
)
236+
237+
for top_point in categorized_points['min']:
238+
self.funscripts[k].add_action(
239+
100,
240+
FFmpegStream.frame_to_millisec(self.get_absolute_framenumber(top_point * (1+self.params.skip_frames)), self.video_info.fps)
235241
)
236-
val = 0 if val != 0 else 100
237242

238243
return status
239244

funscript_editor/algorithms/signal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ def categorize_points(self, signal: list, points: list) -> dict:
485485
dict: dictionary with grouped points { 'min': [], 'max': [] }
486486
"""
487487
avg = Signal.moving_average(signal, w=round(self.fps * self.params.avg_sec_for_local_min_max_extraction))
488-
smothed_signal = Signal.moving_average(signal, w=3)
488+
smothed_signal = Signal.moving_average(signal, w=self.params.local_min_max_filter_len)
489489

490490
grouped_points = {'min': [], 'max': []}
491491
for idx in points:

0 commit comments

Comments
 (0)