2525
2626@dataclass
2727class FunscriptGeneratorParameter :
28- """ Funscript Generator Parameter Dataclass """
28+ """ Funscript Generator Parameter Dataclass with default values """
2929 video_path : str
3030 start_frame : int = 0
3131 skip_frames : int = HYPERPARAMETER ['skip_frames' ]
3232 max_playback_fps : int = 0
3333 direction : str = 'y'
34+ use_zoom : bool = False
3435 track_men : bool = True
3536
3637
@@ -60,6 +61,7 @@ def __init__(self,
6061
6162 self .keypress_queue = Queue (maxsize = 32 )
6263 self .stopped = False
64+ self .x_text_start = 50
6365 self .scone_x = []
6466 self .scone_y = []
6567 self .bboxes = {
@@ -119,7 +121,7 @@ def drawFPS(self, img: np.ndarray) -> np.ndarray:
119121 annotated_img = img .copy ()
120122 fps = (self .params .skip_frames + 1 )* cv2 .getTickFrequency ()/ (cv2 .getTickCount ()- self .timer )
121123 self .tracking_fps .append (fps )
122- cv2 .putText (annotated_img , str (int (fps )) + ' fps' , (75 , 50 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (0 ,0 ,255 ), 2 )
124+ cv2 .putText (annotated_img , str (int (fps )) + ' fps' , (self . x_text_start , 50 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (0 ,0 ,255 ), 2 )
123125 self .timer = cv2 .getTickCount ()
124126 return annotated_img
125127
@@ -137,7 +139,7 @@ def drawText(self, img: np.ndarray, txt: str, y :int = 50, color :tuple = (0,0,2
137139 np.ndarray: opencv image with text
138140 """
139141 annotated_img = img .copy ()
140- cv2 .putText (annotated_img , str (txt ), (75 , y ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , color , 2 )
142+ cv2 .putText (annotated_img , str (txt ), (self . x_text_start , y ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , color , 2 )
141143 return annotated_img
142144
143145
@@ -195,16 +197,16 @@ def min_max_selector(self,
195197 image = np .concatenate ((image_min , image_max ), axis = 1 )
196198
197199 if info != "" :
198- cv2 .putText (image , "Info: " + info , (75 , 75 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (255 ,0 ,0 ), 2 )
200+ cv2 .putText (image , "Info: " + info , (self . x_text_start , 75 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (255 ,0 ,0 ), 2 )
199201
200202 if title_min != "" :
201- cv2 .putText (image , title_min , (75 , 25 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (255 ,0 ,0 ), 2 )
203+ cv2 .putText (image , title_min , (self . x_text_start , 25 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (255 ,0 ,0 ), 2 )
202204
203205 if title_max != "" :
204- cv2 .putText (image , title_max , (image_min .shape [1 ] + 75 , 25 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (255 ,0 ,0 ), 2 )
206+ cv2 .putText (image , title_max , (image_min .shape [1 ] + self . x_text_start , 25 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (255 ,0 ,0 ), 2 )
205207
206208 cv2 .putText (image , "Use 'space' to quit and set the trackbar values" ,
207- (75 , 100 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (255 ,0 ,0 ), 2 )
209+ (self . x_text_start , 100 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (255 ,0 ,0 ), 2 )
208210
209211 self .clear_keypress_queue ()
210212 trackbarValueMin = lower_limit
@@ -213,9 +215,9 @@ def min_max_selector(self,
213215 try :
214216 preview = image .copy ()
215217 cv2 .putText (preview , "Set {} to {}" .format ('Min' , trackbarValueMin ),
216- (75 , 50 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (0 ,0 ,255 ), 2 )
218+ (self . x_text_start , 50 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (0 ,0 ,255 ), 2 )
217219 cv2 .putText (preview , "Set {} to {}" .format ('Max' , trackbarValueMax ),
218- (image_min .shape [1 ] + 75 , 50 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (0 ,0 ,255 ), 2 )
220+ (image_min .shape [1 ] + self . x_text_start , 50 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (0 ,0 ,255 ), 2 )
219221 cv2 .imshow (self .window_name , preview )
220222 if self .was_space_pressed () or cv2 .waitKey (25 ) == ord (' ' ): break
221223 trackbarValueMin = cv2 .getTrackbarPos ("Min" , self .window_name )
@@ -382,13 +384,33 @@ def get_bbox(self, image: np.ndarray, txt: str) -> tuple:
382384 Returns:
383385 tuple: the entered box tuple (x,y,w,h)
384386 """
385- image = self .drawText (image , txt )
386387 image = self .drawText (image , "Press 'space' or 'enter' to continue (sometimes not very responsive)" , y = 75 , color = (255 , 0 , 0 ))
388+ # cv2.namedWindow(self.window_name)
389+ # cv2.createTrackbar("Scale", self.window_name, 1, 10, lambda x: None)
390+
391+ if self .params .use_zoom :
392+ while True :
393+ zoom_bbox = cv2 .selectROI (self .window_name , self .drawText (image , "Zoom selected area" ), False )
394+ if zoom_bbox is None or len (zoom_bbox ) == 0 : continue
395+ if zoom_bbox [2 ] < 100 or zoom_bbox [3 ] < 100 :
396+ self .__logger .error ("The selected zoom area is to small" )
397+ continue
398+ break
399+
400+ image = image [zoom_bbox [1 ]:zoom_bbox [1 ]+ zoom_bbox [3 ], zoom_bbox [0 ]:zoom_bbox [0 ]+ zoom_bbox [2 ]]
401+ image = cv2 .resize (image , None , fx = 2 , fy = 2 )
402+
387403 while True :
388404 bbox = cv2 .selectROI (self .window_name , self .drawText (image , txt ), False )
389405 if bbox is None or len (bbox ) == 0 : continue
390406 if bbox [0 ] == 0 or bbox [1 ] == 0 or bbox [2 ] < 9 or bbox [3 ] < 9 : continue
391- return bbox
407+ break
408+
409+ if self .params .use_zoom :
410+ # NOTE: we upscale the preview by 2
411+ bbox = (round (bbox [0 ]/ 2 )+ zoom_bbox [0 ], round (bbox [1 ]/ 2 )+ zoom_bbox [1 ], round (bbox [2 ]/ 2 ), round (bbox [3 ]/ 2 ))
412+
413+ return bbox
392414
393415
394416 def tracking (self ) -> str :
@@ -452,7 +474,7 @@ def tracking(self) -> str:
452474
453475 last_frame = self .drawFPS (last_frame )
454476 cv2 .putText (last_frame , "Press 'q' if the tracking point shifts or a video cut occured" ,
455- (75 , 75 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (255 ,0 ,0 ), 2 )
477+ (self . x_text_start , 75 ), cv2 .FONT_HERSHEY_SIMPLEX , 0.7 , (255 ,0 ,0 ), 2 )
456478 cv2 .imshow (self .window_name , last_frame )
457479
458480 if self .was_q_pressed () or cv2 .waitKey (1 ) == ord ('q' ):
@@ -556,7 +578,7 @@ def run(self) -> None:
556578 else :
557579 idx_list = sp .get_local_max_and_min_idx (self .score_x , self .fps )
558580
559- if True :
581+ if False :
560582 if self .params .direction != 'x' : self .plot_y_score ('debug_001.png' , idx_list )
561583 self .plot_scores ('debug_002.png' )
562584
0 commit comments