Skip to content

Commit 923be17

Browse files
author
arch
committed
new draft code for roll prediction
1 parent 8c5ac1f commit 923be17

File tree

4 files changed

+80
-36
lines changed

4 files changed

+80
-36
lines changed

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,9 @@ def calculate_score(self, bboxes) -> None:
204204
# this should never happen
205205
self.logger.error('Calculate score not implement for x=%d, y=%d', x, y)
206206

207-
# invert because math angle is ccw
208-
inverted_roll = copy.deepcopy(score['roll'][tracker_number])
209-
score['roll'][tracker_number] = -1*np.array(inverted_roll)
210-
207+
# invert because math angle is ccw, also scale to 0- 100
208+
tmp = score['roll'][tracker_number] # we can not override the list with listcomprehention in python
209+
score['roll'][tracker_number] = [-100*item/(math.pi) for item in tmp]
211210

212211
else:
213212
min_woman_x = min([x[0] for x in woman_center])
@@ -229,11 +228,19 @@ def calculate_score(self, bboxes) -> None:
229228

230229
for metric in score.keys():
231230
if metric in self.funscripts.keys() and self.funscripts[metric].is_inverted():
232-
self.logger.info("%s: Scale Inverted Score to 0 - 100", metric)
233-
self.score[metric] = Signal.scale([-1.0 * x for x in score[metric]], 0, 100)
231+
if metric == 'roll':
232+
self.logger.info("%s: Get absolute inverted Score", metric)
233+
self.score[metric] = [abs(-1.0 * item) for item in score[metric]]
234+
else:
235+
self.logger.info("%s: Scale Inverted Score to 0 - 100", metric)
236+
self.score[metric] = Signal.scale([-1.0 * x for x in score[metric]], 0, 100)
234237
else:
235-
self.logger.info("%s: Scale Score to 0 - 100", metric)
236-
self.score[metric] = Signal.scale(score[metric], 0, 100)
238+
if metric == 'roll':
239+
self.logger.info("%s: Get absolute Score", metric)
240+
self.score[metric] = [abs(item) for item in score[metric]]
241+
else:
242+
self.logger.info("%s: Scale Score to 0 - 100", metric)
243+
self.score[metric] = Signal.scale(score[metric], 0, 100)
237244

238245

239246

@@ -297,15 +304,21 @@ def scale_score(self, status: str, metric : str = 'y') -> None:
297304
image_max = imgMax,
298305
info = status,
299306
title_min = metric + " Minimum",
300-
title_max = metric + " Maximum"
307+
title_max = metric + " Maximum",
308+
recommend_lower = round(min(self.score[metric])) if metric == 'roll' else 0,
309+
recommend_upper = round(max(self.score[metric])) if metric == 'roll' else 99
301310
)
302311
else:
303312
self.logger.warning("Determine min and max failed")
304313
desired_min = 0
305314
desired_max = 99
306315

307316
self.logger.info("Scale score %s to user input", metric)
308-
self.score[metric] = Signal.scale(self.score[metric], desired_min, desired_max)
317+
318+
if metric == 'roll':
319+
self.score[metric] = Signal.scale_with_center(self.score[metric], desired_min, desired_max, 50)
320+
else:
321+
self.score[metric] = Signal.scale(self.score[metric], desired_min, desired_max)
309322

310323

311324
def get_center(self, box: tuple) -> tuple:
@@ -583,7 +596,7 @@ def tracking(self) -> str:
583596
key = self.ui.preview(
584597
last_frame,
585598
frame_num + self.params.start_frame,
586-
texte = ["Scene change detected, Press 'space' or 'enter' to continue tracking or press 'q' to finalize tracking"],
599+
texte = ["Scene change detected, 'space': continue, 'q': stop"],
587600
boxes = boxes_to_draw,
588601
beep = True
589602
)
@@ -609,7 +622,7 @@ def tracking(self) -> str:
609622
key = self.ui.preview(
610623
last_frame,
611624
frame_num + self.params.start_frame,
612-
texte = ["Press 'q' if the tracking point shifts or a video cut occured"],
625+
texte = ["Press 'q' to stop tracking"],
613626
boxes = boxes_to_draw,
614627
)
615628

funscript_editor/algorithms/signal.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,33 @@ def scale(signal: list, lower: float = 0, upper: float = 99) -> list:
156156
return [(float(upper) - float(lower)) * (x - signal_min) / (signal_max - signal_min) + float(lower) for x in signal]
157157

158158

159+
@staticmethod
160+
def scale_with_center(signal: list, lower: float = 0, upper: float = 99, center: float = 50) -> list:
161+
""" Scale an signal (list of float or int) between given lower and upper value with respect to the real center
162+
163+
Args:
164+
signal (list): list with float or int signal values to scale
165+
lower (float): lower scale value
166+
upper (float): upper scale value
167+
center (float): the real center value
168+
169+
Returns:
170+
list: list with scaled signal
171+
"""
172+
if len(signal) == 0:
173+
return signal
174+
175+
if len(signal) == 1:
176+
return [center]
177+
178+
signal_min = min(signal) - center
179+
signal_max = max(signal) - center
180+
signal_max_offset = max(( abs(signal_min), abs(signal_max) ))
181+
signal_min = center - signal_max_offset
182+
signal_max = center + signal_max_offset
183+
184+
return [(float(upper) - float(lower)) * (x - signal_min) / (signal_max - signal_min) + float(lower) for x in signal]
185+
159186
@staticmethod
160187
def scale_with_anomalies(
161188
signal :list,
@@ -554,4 +581,8 @@ def decimate(self,
554581
if len(additional_indexes) > 0:
555582
decimated_indexes = self.merge_points(signal, decimated_indexes, additional_indexes)
556583

584+
if len(decimated_indexes) == 0 and len(signal) > 100:
585+
self.logger.info("Insert start and end point")
586+
decimated_indexes = [1, len(signal)-2]
587+
557588
return decimated_indexes

funscript_editor/config/projection.yaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ vr_he_180_sbs:
1212
name: '3D SBS VR Video 180'
1313
video_filter: 'v360=input=he:in_stereo=sbs:pitch=${pitch}:yaw=${yaw}:roll=${roll}:output=flat:d_fov=${fov}:w=${width}:h=${height}'
1414
parameter:
15-
height: 720
16-
width: 1240
17-
fov: 100
15+
height: 800
16+
width: 800
17+
fov: 80
1818
pitch: -45
1919
yaw: 0
2020
roll: 0
@@ -36,9 +36,9 @@ vr_fisheye_200_sbs:
3636
name: '3D SBS VR Video Fisheye 200'
3737
video_filter: 'v360=input=fisheye:in_stereo=sbs:id_fov=200:pitch=${pitch}:yaw=${yaw}:roll=${roll}:output=flat:d_fov=${fov}:w=${width}:h=${height}'
3838
parameter:
39-
height: 720
40-
width: 1240
41-
fov: 100
39+
height: 800
40+
width: 800
41+
fov: 80
4242
pitch: -45
4343
yaw: 0
4444
roll: 0
@@ -60,9 +60,9 @@ vr_equirect_360_ou:
6060
name: '3D Vertical VR Video 360/180'
6161
video_filter: 'v360=input=equirect:in_stereo=tb:pitch=${pitch}:yaw=${yaw}:roll=${roll}:output=flat:d_fov=${fov}:w=${width}:h=${height}'
6262
parameter:
63-
height: 720
64-
width: 1240
65-
fov: 100
63+
height: 800
64+
width: 800
65+
fov: 80
6666
pitch: -45
6767
yaw: 0
6868
roll: 0
@@ -84,9 +84,9 @@ vr_he_180_ou:
8484
name: '3D Vertical VR Video 180'
8585
video_filter: 'v360=input=he:in_stereo=tb:pitch=${pitch}:yaw=${yaw}:roll=${roll}:output=flat:d_fov=${fov}:w=${width}:h=${height}'
8686
parameter:
87-
height: 720
88-
width: 1240
89-
fov: 100
87+
height: 800
88+
width: 800
89+
fov: 80
9090
pitch: -45
9191
yaw: 0
9292
roll: 0

funscript_editor/ui/opencvui.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,8 @@ def min_max_selector(self,
464464
info: str = "",
465465
title_min: str = "",
466466
title_max: str = "",
467-
lower_limit: int = 0,
468-
upper_limit: int = 99,
467+
recommend_lower: int = 0,
468+
recommend_upper: int = 99,
469469
beep: bool = False) -> tuple:
470470
""" Min Max selection Window
471471
@@ -475,23 +475,23 @@ def min_max_selector(self,
475475
info (str): additional info string th show on the Window
476476
title_min (str): title for the min selection
477477
title_max (str): title for the max selection
478-
lower_limit (int): the lower possible value
479-
upper_limit (int): the highest possible value
478+
recommend_lower (int): recommend lower value
479+
recommend_upper (int): recommend upper value
480480
beep (bool): play notification sound
481481
482482
Returns:
483483
tuple: with selected (min: flaot, max float)
484484
"""
485-
cv2.createTrackbar("Min", self.window_name, lower_limit, upper_limit, lambda _: None)
486-
cv2.createTrackbar("Max", self.window_name, upper_limit, upper_limit, lambda _: None)
485+
cv2.createTrackbar("Min", self.window_name, recommend_lower, 99, lambda _: None)
486+
cv2.createTrackbar("Max", self.window_name, recommend_upper, 99, lambda _: None)
487487
image = np.concatenate((image_min, image_max), axis=1)
488488

489489
if beep:
490490
self.play_notification_sound()
491491

492492
self.clear_keypress_queue()
493-
trackbarValueMin = lower_limit
494-
trackbarValueMax = upper_limit
493+
trackbarValueMin = recommend_lower
494+
trackbarValueMax = recommend_upper
495495
self.logger.info("Waiting for user input")
496496

497497
while True:
@@ -502,7 +502,7 @@ def min_max_selector(self,
502502
self.print_text("Set {} to {}".format('Min', trackbarValueMin))
503503
self.print_text("Set {} to {}".format('Max', trackbarValueMax), text_position_x='column2')
504504
self.print_text("Info: " + info)
505-
self.print_text("Press 'space' or 'enter' to continue", text_position_x='column2')
505+
self.print_text("Press 'space' to continue", text_position_x='column2')
506506
ret = self.show(25)
507507

508508
if self.was_any_accept_key_pressed() or any(ret == x for x in [ord(' '), 13]):
@@ -547,7 +547,7 @@ def bbox_selector(self, image: np.ndarray, txt: str, add_center: bool = False) -
547547
"""
548548
if self.params.use_zoom:
549549
self.set_background_image(image, copy_image=True)
550-
self.print_text("Select area with Mouse and Press 'space' or 'enter' to continue")
550+
self.print_text("Select area with Mouse and Press 'space' to continue")
551551
self.print_text("Zoom selected area")
552552
while True:
553553
zoom_bbox = self.selectROI()
@@ -572,7 +572,7 @@ def bbox_selector(self, image: np.ndarray, txt: str, add_center: bool = False) -
572572
image = cv2.resize(image, None, fx=self.params.zoom_factor, fy=self.params.zoom_factor)
573573

574574
self.set_background_image(image, copy_image=True)
575-
self.print_text("Select area with Mouse and Press 'space' or 'enter' to continue")
575+
self.print_text("Select area with Mouse and Press 'space' to continue")
576576
self.print_text(txt)
577577

578578
while True:
@@ -660,7 +660,7 @@ def get_video_projection_config(self, image :np.ndarray, projection: str) -> dic
660660
parameter_changed = False
661661
preview = FFmpegStream.get_projection(image, config)
662662
self.set_background_image(preview)
663-
self.print_text("Press 'space' or 'enter' to use current viewpoint")
663+
self.print_text("Press 'space' to use current viewpoint")
664664
self.print_text("Press '0' (NULL) to reset view")
665665
final_ui_texte = [ui_texte[k].replace('${val}', str(config['parameter'][k])) for k in ui_texte.keys()]
666666
self.print_text(final_ui_texte)

0 commit comments

Comments
 (0)