@@ -35,7 +35,7 @@ class FunscriptGeneratorParameter:
3535 # No default values
3636 video_path : str # no default value
3737 track_men : bool
38- direction : str
38+ metric : str
3939 projection : str
4040
4141 # Settings
@@ -95,7 +95,7 @@ def __init__(self,
9595 self .score = {
9696 'x' : [],
9797 'y' : [],
98- 'd ' : []
98+ 'euclideanDistance ' : []
9999 }
100100 self .bboxes = {
101101 'Men' : [],
@@ -309,7 +309,7 @@ def calculate_score(self) -> None:
309309 if self .params .track_men :
310310 self .score ['x' ] = [w [0 ] - m [0 ] for w , m in zip (self .bboxes ['Woman' ], self .bboxes ['Men' ])]
311311 self .score ['y' ] = [m [1 ] - w [1 ] for w , m in zip (self .bboxes ['Woman' ], self .bboxes ['Men' ])]
312- self .score ['d ' ] = [np .sqrt (np .sum ((np .array (m [:2 ]) - np .array (w [:2 ])) ** 2 , axis = 0 )) \
312+ self .score ['euclideanDistance ' ] = [np .sqrt (np .sum ((np .array (m [:2 ]) - np .array (w [:2 ])) ** 2 , axis = 0 )) \
313313 for w , m in zip (self .bboxes ['Woman' ], self .bboxes ['Men' ])]
314314 else :
315315 self .score ['x' ] = [w [0 ] - min ([x [0 ] for x in self .bboxes ['Woman' ]]) for w in self .bboxes ['Woman' ]]
@@ -318,29 +318,29 @@ def calculate_score(self) -> None:
318318
319319 self .score ['x' ] = sp .scale_signal (self .score ['x' ], 0 , 100 )
320320 self .score ['y' ] = sp .scale_signal (self .score ['y' ], 0 , 100 )
321- self .score ['d ' ] = sp .scale_signal (self .score ['d ' ], 0 , 100 )
321+ self .score ['euclideanDistance ' ] = sp .scale_signal (self .score ['euclideanDistance ' ], 0 , 100 )
322322
323323
324- def scale_score (self , status : str , direction : str = 'y' ) -> None :
324+ def scale_score (self , status : str , metric : str = 'y' ) -> None :
325325 """ Scale the score to desired stroke high
326326
327327 Note:
328328 We determine the lowerst and highes positions in the score and request the real position from user.
329329
330330 Args:
331331 status (str): a status/info message to display in the window
332- direction (str): scale the 'y' or 'x' score
332+ metric (str): scale the 'y' or 'x' score
333333 """
334334 if len (self .score ['y' ]) < 2 : return
335335
336336 cap = cv2 .VideoCapture (self .params .video_path )
337337 width = int (cap .get (cv2 .CAP_PROP_FRAME_WIDTH ))
338338 height = int (cap .get (cv2 .CAP_PROP_FRAME_HEIGHT ))
339339
340- if direction == 'd ' :
341- min_frame = np .argmin (np .array (self .score ['d ' ])) + self .params .start_frame
342- max_frame = np .argmax (np .array (self .score ['d ' ])) + self .params .start_frame
343- elif direction == 'x' :
340+ if metric == 'euclideanDistance ' :
341+ min_frame = np .argmin (np .array (self .score ['euclideanDistance ' ])) + self .params .start_frame
342+ max_frame = np .argmax (np .array (self .score ['euclideanDistance ' ])) + self .params .start_frame
343+ elif metric == 'x' :
344344 min_frame = np .argmin (np .array (self .score ['x' ])) + self .params .start_frame
345345 max_frame = np .argmax (np .array (self .score ['x' ])) + self .params .start_frame
346346 else :
@@ -370,16 +370,16 @@ def scale_score(self, status: str, direction : str = 'y') -> None:
370370 imgMin = cv2 .resize (imgMin , None , fx = scale , fy = scale )
371371 imgMax = cv2 .resize (imgMax , None , fx = scale , fy = scale )
372372
373- if direction == 'y' :
373+ if metric == 'y' :
374374 title_min = "Bottom"
375- elif direction == 'x' :
375+ elif metric == 'x' :
376376 title_min = "Left"
377377 else :
378378 title_min = "Minimum"
379379
380- if direction == 'y' :
380+ if metric == 'y' :
381381 title_max = "Top"
382- elif direction == 'x' :
382+ elif metric == 'x' :
383383 title_max = "Right"
384384 else :
385385 title_max = "Maximum"
@@ -396,9 +396,9 @@ def scale_score(self, status: str, direction : str = 'y') -> None:
396396 desired_min = 0
397397 desired_max = 99
398398
399- if direction == 'd ' :
400- self .score ['d ' ] = sp .scale_signal (self .score ['d ' ], desired_min , desired_max )
401- elif direction == 'x' :
399+ if metric == 'euclideanDistance ' :
400+ self .score ['euclideanDistance ' ] = sp .scale_signal (self .score ['euclideanDistance ' ], desired_min , desired_max )
401+ elif metric == 'x' :
402402 self .score ['x' ] = sp .scale_signal (self .score ['x' ], desired_min , desired_max )
403403 else :
404404 self .score ['y' ] = sp .scale_signal (self .score ['y' ], desired_min , desired_max )
@@ -796,16 +796,16 @@ def apply_shift(self, frame_number, position: str) -> int:
796796 Args:
797797 position (str): is max or min
798798 """
799- if self .params .direction == 'd ' :
799+ if self .params .metric == 'euclideanDistance ' :
800800 shift_a = self .params .shift_top_points
801- elif self .params .direction == 'x' :
801+ elif self .params .metric == 'x' :
802802 shift_a = self .params .shift_right_points
803803 else :
804804 shift_a = self .params .shift_top_points
805805
806- if self .params .direction == 'd ' :
806+ if self .params .metric == 'euclideanDistance ' :
807807 shift_b = self .params .shift_bottom_points
808- elif self .params .direction == 'x' :
808+ elif self .params .metric == 'x' :
809809 shift_b = self .params .shift_left_points
810810 else :
811811 shift_b = self .params .shift_bottom_points
@@ -832,23 +832,23 @@ def get_score_with_offset(self, idx_dict) -> list:
832832 Returns:
833833 list: score with offset
834834 """
835- if self .params .direction == 'd ' :
835+ if self .params .metric == 'euclideanDistance ' :
836836 offset_a = self .params .top_points_offset
837- elif self .params .direction == 'x' :
837+ elif self .params .metric == 'x' :
838838 offset_a = self .params .right_points_offset
839839 else :
840840 offset_a = self .params .top_points_offset
841841
842- if self .params .direction == 'd ' :
842+ if self .params .metric == 'euclideanDistance ' :
843843 offset_b = self .params .bottom_points_offset
844- elif self .params .direction == 'x' :
844+ elif self .params .metric == 'x' :
845845 offset_b = self .params .left_points_offset
846846 else :
847847 offset_b = self .params .bottom_points_offset
848848
849- if self .params .direction == 'd ' :
850- score = copy .deepcopy (self .score ['d ' ])
851- elif self .params .direction == 'x' :
849+ if self .params .metric == 'euclideanDistance ' :
850+ score = copy .deepcopy (self .score ['euclideanDistance ' ])
851+ elif self .params .metric == 'x' :
852852 score = copy .deepcopy (self .score ['x' ])
853853 else :
854854 score = copy .deepcopy (self .score ['y' ])
@@ -892,9 +892,9 @@ def determin_change_points(self) -> dict:
892892 dict: all local max and min points in score {'min':[idx1, idx2, ...], 'max':[idx1, idx2, ...]}
893893 """
894894 self .logger .info ("Determine change points" )
895- if self .params .direction == 'd ' :
896- idx_dict = sp .get_local_max_and_min_idx (self .score ['d ' ], self .video_info .fps )
897- elif self .params .direction == 'x' :
895+ if self .params .metric == 'euclideanDistance ' :
896+ idx_dict = sp .get_local_max_and_min_idx (self .score ['euclideanDistance ' ], self .video_info .fps )
897+ elif self .params .metric == 'x' :
898898 idx_dict = sp .get_local_max_and_min_idx (self .score ['x' ], self .video_info .fps )
899899 else :
900900 idx_dict = sp .get_local_max_and_min_idx (self .score ['y' ], self .video_info .fps )
@@ -909,9 +909,9 @@ def create_funscript(self, idx_dict: dict) -> None:
909909 {'min':[idx1, idx2, ...], 'max':[idx1, idx2, ...]}
910910 """
911911 if self .params .raw_output :
912- if self .params .direction == 'd ' :
913- output_score = copy .deepcopy (self .score ['d ' ])
914- elif self .params .direction == 'x' :
912+ if self .params .metric == 'euclideanDistance ' :
913+ output_score = copy .deepcopy (self .score ['euclideanDistance ' ])
914+ elif self .params .metric == 'x' :
915915 output_score = copy .deepcopy (self .score ['x' ])
916916 else :
917917 output_score = copy .deepcopy (self .score ['y' ])
@@ -925,16 +925,16 @@ def create_funscript(self, idx_dict: dict) -> None:
925925 else :
926926 output_score = self .get_score_with_offset (idx_dict )
927927
928- if self .params .direction == 'd ' :
928+ if self .params .metric == 'euclideanDistance ' :
929929 threshold_a = self .params .bottom_threshold
930- elif self .params .direction == 'x' :
930+ elif self .params .metric == 'x' :
931931 threshold_a = self .params .left_threshold
932932 else :
933933 threshold_a = self .params .bottom_threshold
934934
935- if self .params .direction == 'd ' :
935+ if self .params .metric == 'euclideanDistance ' :
936936 threshold_b = self .params .top_threshold
937- elif self .params .direction == 'x' :
937+ elif self .params .metric == 'x' :
938938 threshold_b = self .params .right_threshold
939939 else :
940940 threshold_b = self .params .top_threshold
@@ -959,9 +959,8 @@ def create_funscript(self, idx_dict: dict) -> None:
959959 def run (self ) -> None :
960960 """ The Funscript Generator Thread Function """
961961 try :
962- if self .params .direction == 'd' and not self .params .track_men :
963- self .finished ("Tracking with 'd' and no men tracker is not implemented!" , False )
964- return
962+ if self .params .metric not in ['x' , 'y' ]:
963+ self .params .track_men = True # we need 2 tracking points
965964
966965 if self .video_info .fps < 31.0 and self .params .skip_frames > 0 :
967966 self .logger .warning ("The Video has less than 30 frames per seconds and you have set skip_frames to %d " \
@@ -980,7 +979,7 @@ def run(self) -> None:
980979
981980 if len (self .score ['y' ]) >= HYPERPARAMETER ['min_frames' ]:
982981 self .logger .info ("Scale score" )
983- self .scale_score (status , direction = self .params .direction )
982+ self .scale_score (status , metric = self .params .metric )
984983
985984 if len (self .score ['y' ]) < HYPERPARAMETER ['min_frames' ]:
986985 self .finished (status + ' -> Tracking time insufficient' , False )
0 commit comments