Skip to content

Commit c6ed34e

Browse files
author
arch
committed
add ui to select a line
1 parent 53203f4 commit c6ed34e

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ def scale_score(self, status: str, metric : str = 'y') -> None:
270270
imgMin = FFmpegStream.get_projection(imgMin, self.projection_config)
271271
imgMax = FFmpegStream.get_projection(imgMax, self.projection_config)
272272

273+
if metric == 'roll':
274+
max_distance_frame_num = np.argmax(np.array([abs(x) for x in self.score['distance']])) + self.params.start_frame
275+
max_distance_frame = FFmpegStream.get_frame(self.params.video_path, max_distance_frame_num)
276+
max_distance_frame = FFmpegStream.get_projection(max_distance_frame, self.projection_config)
277+
center_line = self.ui.line_selector(max_distance_frame, "draw line on center of dick")
278+
print('center line', center_line)
279+
273280
min_tracking_points = self.get_tracking_points_by_frame_number(min_frame - self.params.start_frame)
274281
max_tracking_points = self.get_tracking_points_by_frame_number(max_frame - self.params.start_frame)
275282

@@ -281,6 +288,7 @@ def scale_score(self, status: str, metric : str = 'y') -> None:
281288

282289
# print('min_tracking_points', min_tracking_points, 'max_tracking_points', max_tracking_points)
283290

291+
284292
(desired_min, desired_max) = self.ui.min_max_selector(
285293
image_min = imgMin,
286294
image_max = imgMax,

funscript_editor/ui/opencvui.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,37 @@ def was_key_pressed(self, key: str) -> bool:
9999
return False
100100

101101

102+
class DrawSingleLineWidget(object):
103+
def __init__(self, background_img, window_name, preview_scaling):
104+
self.original_image = background_img
105+
self.clone = self.original_image.copy()
106+
self.window_name = window_name
107+
self.preview_scaling = preview_scaling
108+
109+
cv2.namedWindow(window_name)
110+
cv2.setMouseCallback(window_name, self.extract_coordinates)
111+
112+
self.start_coordinate = None
113+
self.end_coordinate = None
114+
115+
def extract_coordinates(self, event, x, y, flags, parameters):
116+
x = round(x/self.preview_scaling)
117+
y = round(y/self.preview_scaling)
118+
119+
if event == cv2.EVENT_LBUTTONDOWN:
120+
self.start_coordinate = (x,y)
121+
122+
elif event == cv2.EVENT_LBUTTONUP:
123+
self.end_coordinate = (x,y)
124+
self.clone = self.original_image.copy()
125+
cv2.line(self.clone, self.start_coordinate, self.end_coordinate, (36,255,12), 2)
126+
127+
def show_image(self):
128+
return self.clone
129+
130+
def get_result(self):
131+
return [ self.start_coordinate, self.end_coordinate ]
132+
102133

103134
class OpenCV_GUI(KeypressHandler):
104135
""" High Level OpenCV GUI.
@@ -473,6 +504,33 @@ def play_beep():
473504
self.logger.warning("Notification sound file not found (%s)", self.params.notification_sound_file)
474505

475506

507+
def line_selector(self,
508+
image: np.ndarray,
509+
txt: str):
510+
""" Line Selector Widget
511+
512+
Args:
513+
image (np.ndarray): background image
514+
txt (str): text to display
515+
516+
Returns:
517+
list: start and endpoint of line
518+
"""
519+
520+
line_widget = DrawSingleLineWidget(image, self.window_name, self.monitor_preview_scaling)
521+
while True:
522+
self.set_background_image(line_widget.show_image(), copy_image=False)
523+
self.print_text(txt)
524+
self.print_text("Press 'space' to continue")
525+
ret = self.show(5)
526+
527+
if self.was_any_accept_key_pressed() or any(ret == x for x in [ord(' '), 13]):
528+
result = line_widget.get_result()
529+
if result[0] is not None and result[1] is not None:
530+
if abs(result[0][0] - result[1][0]) + abs(result[0][1] - result[1][1]) > 10:
531+
return result
532+
533+
476534
def min_max_selector(self,
477535
image_min: np.ndarray,
478536
image_max: np.ndarray,

0 commit comments

Comments
 (0)