Skip to content

Commit 640f359

Browse files
author
arch
committed
add offset function
1 parent 025d0e7 commit 640f359

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

docs/app/docs/user-guide/config.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Config Files:
2424
- `min_frames` (int): Specify the minimum required frames for the tracking. Wee need this parameter to ensure there is at leas two strokes in the tracking result.
2525
- `shift_top_points` (int): Shift predicted top points by given frame number. Positive values delay the position and negative values result in an earlier position.
2626
- `shift_bottom_points` (int): Shift predicted bottom points by given frame number. Positive values delay the position and negative values result in an earlier position.
27+
- `top_points_offset` (float): An fix offset to the top points (positive values move the point up and negative values move the point down). The offset respect the user defined upper and lower limit.
28+
- `bottom_points_offset` (float): An fix offset to the bottom points (positive values move the point up and negative values move the point down). The offset respect the user defined upper and lower limit.
2729
- `top_threshold` (float): Define the top threshold. All top points greater than `(max - threshold)` will be set to the specified max value. Set 0.0 to disable this function.
2830
- `bottom_threshold` (float): Define the bottom threshold. All bottom points lower than `(min + threshold)` will be set to the specified min value. Set 0.0 to disable this function.
2931

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cv2
44
import json
5+
import copy
56
import time
67
import logging
78

@@ -37,6 +38,8 @@ class FunscriptGeneratorParameter:
3738
use_zoom: bool = SETTINGS['use_zoom']
3839
shift_bottom_points :int = int(HYPERPARAMETER['shift_bottom_points'])
3940
shift_top_points :int = int(HYPERPARAMETER['shift_top_points'])
41+
top_points_offset :float = float(HYPERPARAMETER['top_points_offset'])
42+
bottom_points_offset :float = float(HYPERPARAMETER['bottom_points_offset'])
4043
use_equirectangular :bool = SETTINGS['use_equirectangular']
4144
equirectangular_scaling :float = max((0.2, float(SETTINGS['equirectangular_scaling'])))
4245
zoom_factor :float = max((1.0, float(SETTINGS['zoom_factor'])))
@@ -710,6 +713,28 @@ def apply_shift(self, frame_number, position: str) -> int:
710713

711714
return self.params.start_frame + frame_number
712715

716+
def get_score_with_offset(self, idx_dict) -> list:
717+
""" Apply the offsets form config file
718+
719+
Args:
720+
idx_dict (dict): the idx dictionary with {'min':[], 'max':[]} idx lists
721+
722+
Returns:
723+
list: score with offset
724+
"""
725+
if self.params.direction == 'x':
726+
return self.score_x
727+
728+
score = copy.deepcopy(self.score_y)
729+
score_min, score_max = min(score), max(score)
730+
for idx in idx_dict['min']:
731+
score[idx] = max(( score_min, min((score_max, score[idx] + self.params.bottom_points_offset)) ))
732+
733+
for idx in idx_dict['max']:
734+
score[idx] = max(( score_min, min((score_max, score[idx] + self.params.top_points_offset)) ))
735+
736+
return score
737+
713738

714739
def run(self) -> None:
715740
""" The Funscript Generator Thread Function """
@@ -739,7 +764,7 @@ def run(self) -> None:
739764
if self.params.direction != 'x':
740765
self.plot_y_score('debug_002.png', idx_list)
741766

742-
output_score = self.score_y if self.params.direction != 'x' else self.score_x
767+
output_score = self.get_score_with_offset(idx_dict)
743768
for idx in idx_dict['min']:
744769
self.funscript.add_action(
745770
min(output_score) \

funscript_editor/config/hyperparameter.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ shift_top_points: 0
2121
# and negative values result in an earlier position.
2222
shift_bottom_points: 0
2323

24+
# An fix offset to the top points (positive values move the point up and negative values
25+
# move the point down). The offset respect the user defined upper and lower limit.
26+
top_points_offset: 5.0
27+
28+
# An fix offset to the bottom points (positive values move the point up and negative values
29+
# move the point down). The offset respect the user defined upper and lower limit.
30+
bottom_points_offset: -15.0
31+
2432
# Define the top threshold. All top points greater than (max - threshold) will be set to
2533
# the specified max value. Set 0.0 to disable this function.
2634
top_threshold: 5.0
2735

2836
# Define the bottom threshold. All bottom points lower than (min + threshold) will be set to
2937
# the specified min value. Set 0.0 to disable this function.
30-
bottom_threshold: 10.0
38+
bottom_threshold: 5.0

0 commit comments

Comments
 (0)