Skip to content

Commit 2a86d93

Browse files
author
arch
committed
add raw output
1 parent 355d2f3 commit 2a86d93

File tree

2 files changed

+55
-29
lines changed

2 files changed

+55
-29
lines changed

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class FunscriptGeneratorParameter:
3333
start_frame: int = 0 # default is video start (input: set current video position)
3434
end_frame: int = -1 # default is video end (-1)
3535
track_men: bool = True # set by userinput at start (message box)
36+
raw_output: bool = False
3637

3738
# Settings
3839
max_playback_fps: int = max((0, int(SETTINGS['max_playback_fps'])))
@@ -222,6 +223,7 @@ def append_interpolated_bbox(self, bbox :tuple, target: str) -> None:
222223
bbox (tuple): the new tracking box (x,y,w,h)
223224
target (str): the target where to save the interpolated tracking boxes
224225
"""
226+
# TODO: interpolate after tracking when all data points are know
225227
if self.params.skip_frames > 0 and len(self.bboxes[target]) > 0:
226228
back_in_time = 2
227229
if len(self.bboxes[target]) < (self.params.skip_frames+1)*back_in_time:
@@ -854,7 +856,13 @@ def get_score_with_offset(self, idx_dict) -> list:
854856
else:
855857
offset_b = self.params.bottom_points_offset
856858

857-
score = copy.deepcopy(self.score['y'])
859+
if self.params.direction == 'd':
860+
score = copy.deepcopy(self.score['d'])
861+
elif self.params.direction == 'x':
862+
score = copy.deepcopy(self.score['x'])
863+
else:
864+
score = copy.deepcopy(self.score['y'])
865+
858866
score_min, score_max = min(score), max(score)
859867

860868
for idx in idx_dict['max']:
@@ -870,7 +878,7 @@ def apply_kalman_filter(self) -> None:
870878
""" Apply Kalman Filter to the tracking prediction """
871879
if len(self.bboxes['Woman']) < self.video_info.fps: return
872880

873-
# TODO: we should use the center of the tracking box not x0,y0 of the box
881+
# TODO: we should use the center of the tracking box not x0, y0 of the box
874882

875883
self.logger.info("Apply kalman filter")
876884
kalman = KalmanFilter2D(self.video_info.fps)
@@ -910,37 +918,52 @@ def create_funscript(self, idx_dict: dict) -> None:
910918
idx_dict (dict): dictionary with all local max and min points in score
911919
{'min':[idx1, idx2, ...], 'max':[idx1, idx2, ...]}
912920
"""
913-
output_score = self.get_score_with_offset(idx_dict)
921+
if self.params.raw_output:
922+
if self.params.direction == 'd':
923+
output_score = copy.deepcopy(self.score['d'])
924+
elif self.params.direction == 'x':
925+
output_score = copy.deepcopy(self.score['x'])
926+
else:
927+
output_score = copy.deepcopy(self.score['y'])
914928

915-
if self.params.direction == 'd':
916-
threshold_a = self.params.bottom_threshold
917-
elif self.params.direction == 'x':
918-
threshold_a = self.params.left_threshold
919-
else:
920-
threshold_a = self.params.bottom_threshold
929+
for idx in range(len(output_score)):
930+
self.funscript.add_action(
931+
output_score[idx],
932+
FFmpegStream.frame_to_millisec(self.apply_shift(idx, 'none'), self.video_info.fps)
933+
)
921934

922-
if self.params.direction == 'd':
923-
threshold_b = self.params.top_threshold
924-
elif self.params.direction == 'x':
925-
threshold_b = self.params.right_threshold
926935
else:
927-
threshold_b = self.params.top_threshold
936+
output_score = self.get_score_with_offset(idx_dict)
928937

929-
for idx in idx_dict['min']:
930-
self.funscript.add_action(
931-
min(output_score) \
932-
if output_score[idx] < min(output_score) + threshold_a \
933-
else round(output_score[idx]),
934-
FFmpegStream.frame_to_millisec(self.apply_shift(idx, 'min'), self.video_info.fps)
935-
)
938+
if self.params.direction == 'd':
939+
threshold_a = self.params.bottom_threshold
940+
elif self.params.direction == 'x':
941+
threshold_a = self.params.left_threshold
942+
else:
943+
threshold_a = self.params.bottom_threshold
936944

937-
for idx in idx_dict['max']:
938-
self.funscript.add_action(
939-
max(output_score) \
940-
if output_score[idx] > max(output_score) - threshold_b \
941-
else round(output_score[idx]),
942-
FFmpegStream.frame_to_millisec(self.apply_shift(idx, 'max'), self.video_info.fps)
943-
)
945+
if self.params.direction == 'd':
946+
threshold_b = self.params.top_threshold
947+
elif self.params.direction == 'x':
948+
threshold_b = self.params.right_threshold
949+
else:
950+
threshold_b = self.params.top_threshold
951+
952+
for idx in idx_dict['min']:
953+
self.funscript.add_action(
954+
min(output_score) \
955+
if output_score[idx] < min(output_score) + threshold_a \
956+
else round(output_score[idx]),
957+
FFmpegStream.frame_to_millisec(self.apply_shift(idx, 'min'), self.video_info.fps)
958+
)
959+
960+
for idx in idx_dict['max']:
961+
self.funscript.add_action(
962+
max(output_score) \
963+
if output_score[idx] > max(output_score) - threshold_b \
964+
else round(output_score[idx]),
965+
FFmpegStream.frame_to_millisec(self.apply_shift(idx, 'max'), self.video_info.fps)
966+
)
944967

945968

946969
def run(self) -> None:
@@ -949,6 +972,9 @@ def run(self) -> None:
949972
self.finished("Tracking with 'd' and no men tracker is not implemented!", False)
950973
return
951974

975+
if self.params.raw_output:
976+
self.logger.warning("Raw output is enabled!")
977+
952978
# NOTE: score['y'] and score['x'] should have the same number size so it should be enouth to check one score length
953979
with Listener(on_press=self.on_key_press) as listener:
954980
status = self.tracking()

funscript_editor/config/hyperparameter.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# This parameter specifies how many frames are skipped and interpolated during tracking.
88
# Increase this parameter to improve the processing speed on slow hardware. But higher
99
# values result in poorer predictions!
10-
skip_frames: 1
10+
skip_frames: 0
1111

1212
# Specify the window size for the calculation of the reference value for the local min
1313
# and max search.

0 commit comments

Comments
 (0)