Skip to content

Commit d3aa1fc

Browse files
author
arch
committed
add quadratic interpolation
1 parent 3518de8 commit d3aa1fc

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

environment.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ dependencies:
66
- ca-certificates=2021.5.25=haa95532_1
77
- certifi=2021.5.30=py39haa95532_0
88
- freetype=2.10.4=hd328e21_0
9+
- icc_rt=2019.0.0=h0cc432a_1
910
- icu=58.2=ha925a31_3
1011
- intel-openmp=2021.2.0=haa95532_616
1112
- jpeg=9b=hb83a4c4_2
@@ -26,6 +27,7 @@ dependencies:
2627
- python=3.9.5=h6244533_3
2728
- pyyaml=5.4.1=py39h2bbff1b_1
2829
- qt=5.9.7=vc14h73c81de_0
30+
- scipy=1.6.2=py39h66253e8_1
2931
- setuptools=52.0.0=py39haa95532_0
3032
- sip=4.19.13=py39hd77b12b_0
3133
- six=1.16.0=pyhd3eb1b0_0

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from datetime import datetime
2020
from funscript_editor.data.ffmpegstream import FFmpegStream, VideoInfo
2121
from funscript_editor.algorithms.kalmanfilter import KalmanFilter2D
22+
from scipy.interpolate import interp1d
2223

2324
import funscript_editor.algorithms.signalprocessing as sp
2425
import numpy as np
@@ -222,12 +223,47 @@ def append_interpolated_bbox(self, bbox :tuple, target: str) -> None:
222223
target (str): the target where to save the interpolated tracking boxes
223224
"""
224225
if self.params.skip_frames > 0 and len(self.bboxes[target]) > 0:
225-
for i in range(1, self.params.skip_frames+1):
226-
x0 = np.interp(i, [0, self.params.skip_frames+1], [self.bboxes[target][-1][0], bbox[0]])
227-
y0 = np.interp(i, [0, self.params.skip_frames+1], [self.bboxes[target][-1][1], bbox[1]])
228-
w = np.interp(i, [0, self.params.skip_frames+1], [self.bboxes[target][-1][2], bbox[2]])
229-
h = np.interp(i, [0, self.params.skip_frames+1], [self.bboxes[target][-1][3], bbox[3]])
230-
self.bboxes[target].append((x0, y0, w, h))
226+
back_in_time = 2
227+
if len(self.bboxes[target]) < (self.params.skip_frames+1)*back_in_time:
228+
for i in range(1, self.params.skip_frames+1):
229+
# use linear interpolation for the first steps
230+
x0 = np.interp(i, [0, self.params.skip_frames+1], [self.bboxes[target][-1][0], bbox[0]])
231+
y0 = np.interp(i, [0, self.params.skip_frames+1], [self.bboxes[target][-1][1], bbox[1]])
232+
w = np.interp(i, [0, self.params.skip_frames+1], [self.bboxes[target][-1][2], bbox[2]])
233+
h = np.interp(i, [0, self.params.skip_frames+1], [self.bboxes[target][-1][3], bbox[3]])
234+
self.bboxes[target].append((x0, y0, w, h))
235+
else:
236+
# switch to quadratic interpolation as soon as there is enough data for interpolation
237+
x = [-1*(self.params.skip_frames+1)*back_in_time + x + 1 for x in range((self.params.skip_frames+1)*back_in_time)] \
238+
+ [self.params.skip_frames+1]
239+
240+
fx0 = interp1d(
241+
x,
242+
[item[0] for item in self.bboxes[target][-1*(self.params.skip_frames+1)*back_in_time:]] + [bbox[0]],
243+
kind = 'quadratic'
244+
)
245+
246+
fy0 = interp1d(
247+
x,
248+
[item[1] for item in self.bboxes[target][-1*(self.params.skip_frames+1)*back_in_time:]] + [bbox[1]],
249+
kind = 'quadratic'
250+
)
251+
252+
fw = interp1d(
253+
x,
254+
[item[2] for item in self.bboxes[target][-1*(self.params.skip_frames+1)*back_in_time:]] + [bbox[2]],
255+
kind = 'quadratic'
256+
)
257+
258+
fh = interp1d(
259+
x,
260+
[item[3] for item in self.bboxes[target][-1*(self.params.skip_frames+1)*back_in_time:]] + [bbox[3]],
261+
kind = 'quadratic'
262+
)
263+
264+
for i in range(1, self.params.skip_frames+1):
265+
self.bboxes[target].append((fx0(i), fy0(i), fw(i), fh(i)))
266+
231267
self.bboxes[target].append(bbox)
232268

233269

@@ -929,5 +965,10 @@ def run(self) -> None:
929965
return
930966

931967
idx_dict = self.determin_change_points()
968+
969+
idx_list = [x for k in ['min', 'max'] for x in idx_dict[k]]
970+
idx_list.sort()
971+
self.plot_y_score('debug.png', idx_list)
972+
932973
self.create_funscript(idx_dict)
933974
self.finished(status, True)

funscript_editor/config/settings.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use_zoom: False
1111
zoom_factor: 4.0
1212

1313
# Specify the tracking direction. Allowed values are `'x'` and `'y'`.
14-
tracking_direction: 'd'
14+
tracking_direction: 'y'
1515

1616
# Limit the max player speed in the tracking preview window (0 = disable limit)
17-
max_playback_fps: 0
17+
max_playback_fps: 120
1818

1919
# Set the preview image scaling factor. With a value of 1.0, the window should fill the height
2020
# or width of the screen depending on the aspect ratio of the video.

funscript_editor/ui/funscript_editor_window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ def __funscript_generated(self, funscript, status, success):
324324
self.__save_funscript()
325325
self.video_player.show_message(status)
326326
if success:
327-
self.__logger.info(status)
327+
self.__logger.info("Completed: " + status)
328328
else:
329-
self.__logger.error(status)
329+
self.__logger.error("Failed: " + status)
330330

331331
def __delete_current_action(self):
332332
if self.funscript is None: return

0 commit comments

Comments
 (0)