Skip to content

Commit a0ac0c1

Browse files
author
arch
committed
improve preview scaling
1 parent 8e0dceb commit a0ac0c1

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def min_max_selector(self,
280280
(self.x_text_start, 50), cv2.FONT_HERSHEY_SIMPLEX, self.font_size, (0,0,255), 2)
281281
cv2.putText(preview, "Set {} to {}".format('Max', trackbarValueMax),
282282
(image_min.shape[1] + self.x_text_start, 50), cv2.FONT_HERSHEY_SIMPLEX, self.font_size, (0,0,255), 2)
283-
cv2.imshow(self.window_name, self.preview_scaling(preview))
283+
cv2.imshow(self.window_name, self.preview_scaling(preview, 1.1))
284284
if self.was_space_pressed() or cv2.waitKey(25) == ord(' '): break
285285
trackbarValueMin = cv2.getTrackbarPos("Min", self.window_name)
286286
trackbarValueMax = cv2.getTrackbarPos("Max", self.window_name)
@@ -352,9 +352,9 @@ def scale_score(self, status: str, direction : str = 'y') -> None:
352352
imgMax = imgMax[:int(imgMax.shape[0]/2), :]
353353

354354
if PROJECTION[self.params.projection]['parameter']['width'] > 0:
355-
scale = PROJECTION[self.params.projection]['parameter']['width'] / float(2*imgMax.shape[1])
355+
scale = PROJECTION[self.params.projection]['parameter']['width'] / float(1.75*imgMax.shape[1])
356356
else:
357-
scale = PROJECTION[self.params.projection]['parameter']['height'] / float(2*imgMax.shape[1])
357+
scale = PROJECTION[self.params.projection]['parameter']['height'] / float(1.75*imgMax.shape[0])
358358
imgMin = cv2.resize(imgMin, None, fx=scale, fy=scale)
359359
imgMax = cv2.resize(imgMax, None, fx=scale, fy=scale)
360360

@@ -451,20 +451,21 @@ def delete_last_tracking_predictions(self, num :int) -> None:
451451
if self.params.track_men: del self.bboxes['Men'][-1]
452452

453453

454-
def preview_scaling(self, preview_image :np.ndarray) -> np.ndarray:
454+
def preview_scaling(self, preview_image :np.ndarray, post_scale :float = 1.0) -> np.ndarray:
455455
""" Scale image for preview
456456
457457
Args:
458458
preview_image (np.ndarray): opencv image
459+
post_scale (float, optional): additional scaling factor
459460
460461
Returns:
461462
np.ndarray: scaled opencv image
462463
"""
463464
return cv2.resize(
464465
preview_image,
465466
None,
466-
fx=self.params.preview_scaling,
467-
fy=self.params.preview_scaling
467+
fx=self.params.preview_scaling*post_scale,
468+
fy=self.params.preview_scaling*post_scale
468469
)
469470

470471

@@ -678,7 +679,7 @@ def tracking(self) -> str:
678679

679680
if self.was_key_pressed('q') or cv2.waitKey(1) == ord('q'):
680681
status = 'Tracking stopped by user'
681-
self.delete_last_tracking_predictions(int((self.get_average_tracking_fps()+1)*2.2))
682+
self.delete_last_tracking_predictions(int((self.get_average_tracking_fps()+1)*2.0))
682683
break
683684

684685
(successWoman, bboxWoman) = trackerWoman.result()
@@ -756,7 +757,8 @@ def finished(self, status: str, success :bool) -> None:
756757
status (str): a process status/error message
757758
success (bool): True if funscript was generated else False
758759
"""
759-
cv2.destroyWindow(self.window_name)
760+
try: cv2.destroyWindow(self.window_name)
761+
except: pass
760762
self.funscriptCompleted.emit(self.funscript, status, success)
761763

762764

@@ -907,6 +909,10 @@ def create_funscript(self, idx_dict: dict) -> None:
907909

908910
def run(self) -> None:
909911
""" The Funscript Generator Thread Function """
912+
if self.params.direction == 'd' and not self.params.track_men:
913+
self.finished("Tracking with 'd' and no men tracker is not implemented!", False)
914+
return
915+
910916
# NOTE: score['y'] and score['x'] should have the same number size so it should be enouth to check one score length
911917
with Listener(on_press=self.on_key_press) as listener:
912918
status = self.tracking()

funscript_editor/config/hyperparameter.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ skip_frames: 1
1111

1212
# Specify the window size for the calculation of the reference value for the local min
1313
# and max search.
14-
avg_sec_for_local_min_max_extraction: 1.9
14+
avg_sec_for_local_min_max_extraction: 2.0
1515

1616
# Specify the minimum required frames for the tracking. Wee need this parameter to
1717
# ensure there is at leas two strokes in the tracking result.

funscript_editor/config/settings.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ preview_scaling: 0.6
2626
# Available Options:
2727
# - 'flat': 2D Videos
2828
# - 'vr_he_sbs': 3D VR Side-By-Side Video
29-
projection: 'flat'
29+
projection: 'vr_he_sbs'

0 commit comments

Comments
 (0)