<s> import cv2 <EOL> import sys <EOL> import collections <EOL> import inspect <EOL> from butterflow . settings import default as settings <EOL> from butterflow . __init__ import __version__ <EOL> def fr_big_enough_to_draw_on ( fr , w_fits , h_fits ) : <EOL> scale = min ( float ( fr . shape [ <NUM_LIT:1> ] ) / float ( w_fits ) , <EOL> float ( fr . shape [ <NUM_LIT:0> ] ) / float ( h_fits ) ) <EOL> return scale >= <NUM_LIT:1.0> <EOL> def draw_fr_marker ( fr , fill = True ) : <EOL> if not fr_big_enough_to_draw_on ( fr , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] ) : <EOL> return <EOL> w = fr . shape [ <NUM_LIT:1> ] <EOL> h = fr . shape [ <NUM_LIT:0> ] <EOL> center = ( int ( w - ( settings [ '<STR_LIT>' ] + settings [ '<STR_LIT>' ] ) ) , <EOL> int ( h - settings [ '<STR_LIT>' ] - settings [ '<STR_LIT>' ] ) ) <EOL> cv2 . circle ( fr , <EOL> center , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] ) <EOL> cv2 . circle ( fr , <EOL> center , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] if fill else settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] ) <EOL> def draw_progress_bar ( fr , progress = <NUM_LIT:0.0> ) : <EOL> if not fr_big_enough_to_draw_on ( fr , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] ) : <EOL> return <EOL> w = fr . shape [ <NUM_LIT:1> ] <EOL> h = fr . shape [ <NUM_LIT:0> ] <EOL> draw_strk = lambda x , y , shift_x , shift_y , ext_x , ext_y : cv2 . rectangle ( fr , <EOL> ( x [ <NUM_LIT:0> ] + shift_x - ext_x , x [ <NUM_LIT:1> ] + shift_y - ext_y ) , <EOL> ( y [ <NUM_LIT:0> ] + shift_x + ext_x , y [ <NUM_LIT:1> ] + shift_y + ext_y ) , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] ) <EOL> draw_rect = lambda x , y : cv2 . rectangle ( fr , <EOL> x , <EOL> y , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] ) <EOL> t_v1 = ( int ( w * settings [ '<STR_LIT>' ] ) , int ( h * settings [ '<STR_LIT>' ] ) ) <EOL> t_v2 = ( int ( w * ( <NUM_LIT:1> - settings [ '<STR_LIT>' ] ) ) , t_v1 [ <NUM_LIT:1> ] + <EOL> settings [ '<STR_LIT>' ] ) <EOL> draw_strk ( t_v1 , t_v2 , <NUM_LIT:0> , - settings [ '<STR_LIT>' ] , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> draw_rect ( t_v1 , t_v2 ) <EOL> b_v1 = ( t_v1 [ <NUM_LIT:0> ] , t_v2 [ <NUM_LIT:1> ] + <NUM_LIT:2> * settings [ '<STR_LIT>' ] + <EOL> settings [ '<STR_LIT>' ] ) <EOL> b_v2 = ( t_v2 [ <NUM_LIT:0> ] , b_v1 [ <NUM_LIT:1> ] + settings [ '<STR_LIT>' ] ) <EOL> draw_strk ( b_v1 , b_v2 , <NUM_LIT:0> , settings [ '<STR_LIT>' ] , <NUM_LIT:1> , <NUM_LIT:0> ) <EOL> draw_rect ( b_v1 , b_v2 ) <EOL> l_v1 = t_v1 <EOL> l_v2 = ( b_v1 [ <NUM_LIT:0> ] + settings [ '<STR_LIT>' ] , b_v1 [ <NUM_LIT:1> ] + settings [ '<STR_LIT>' ] ) <EOL> draw_strk ( l_v1 , l_v2 , - settings [ '<STR_LIT>' ] , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> draw_rect ( l_v1 , l_v2 ) <EOL> r_v1 = ( t_v2 [ <NUM_LIT:0> ] - settings [ '<STR_LIT>' ] , t_v1 [ <NUM_LIT:1> ] ) <EOL> r_v2 = b_v2 <EOL> draw_strk ( r_v1 , r_v2 , settings [ '<STR_LIT>' ] , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> draw_rect ( r_v1 , r_v2 ) <EOL> pad = settings [ '<STR_LIT>' ] + settings [ '<STR_LIT>' ] <EOL> max_w = int ( r_v2 [ <NUM_LIT:0> ] - pad ) <EOL> min_w = int ( l_v1 [ <NUM_LIT:0> ] + pad ) <EOL> bar_v1 = ( t_v1 [ <NUM_LIT:0> ] + pad , l_v1 [ <NUM_LIT:1> ] + pad ) <EOL> bar_v2 = ( max ( min_w , min ( max_w , int ( max_w * progress ) ) ) , b_v2 [ <NUM_LIT:1> ] - pad ) <EOL> if progress > <NUM_LIT:0> : <EOL> draw_strk ( bar_v1 , bar_v2 , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> draw_rect ( bar_v1 , bar_v2 ) <EOL> def draw_debug_text ( fr , text_type , rate , flow_fn , tot_frs_wrt , pair_a , pair_b , <EOL> btw_idx , fr_type , is_dup , tgt_frs , frs_wrt , sub , sub_idx , <EOL> subs_to_render , drp_every , dup_every , src_seen , frs_int , <EOL> frs_drp , frs_dup ) : <EOL> if not fr_big_enough_to_draw_on ( fr , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] ) : <EOL> return <EOL> w = fr . shape [ <NUM_LIT:1> ] <EOL> h = fr . shape [ <NUM_LIT:0> ] <EOL> scale = min ( min ( float ( w ) / settings [ '<STR_LIT>' ] , settings [ '<STR_LIT>' ] ) , <EOL> min ( float ( h ) / settings [ '<STR_LIT>' ] , settings [ '<STR_LIT>' ] ) ) <EOL> if text_type in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> color = settings [ '<STR_LIT>' ] <EOL> else : <EOL> color = settings [ '<STR_LIT>' ] <EOL> draw_strk = lambda x , y : cv2 . putText ( fr , <EOL> x , <EOL> y , <EOL> settings [ '<STR_LIT>' ] , <EOL> scale , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] ) <EOL> draw_text = lambda x , y : cv2 . putText ( fr , <EOL> x , <EOL> y , <EOL> settings [ '<STR_LIT>' ] , <EOL> scale , <EOL> color , <EOL> settings [ '<STR_LIT>' ] , <EOL> settings [ '<STR_LIT>' ] ) <EOL> txt = "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> txt = txt . format ( __version__ , sys . platform , w , h , rate ) <EOL> argspec = inspect . getargspec ( flow_fn ) <EOL> defaults = list ( argspec . defaults ) <EOL> args = argspec . args [ - len ( defaults ) : ] <EOL> flow_kwargs = collections . OrderedDict ( zip ( args , defaults ) ) <EOL> if flow_kwargs is not None : <EOL> flow_format = '<STR_LIT>' <EOL> i = <NUM_LIT:0> <EOL> for k , v in flow_kwargs . items ( ) : <EOL> value_format = "<STR_LIT:{}>" <EOL> if isinstance ( v , bool ) : <EOL> value_format = "<STR_LIT>" <EOL> flow_format += ( "<STR_LIT>" + value_format ) . format ( k . capitalize ( ) [ : <NUM_LIT:1> ] , v ) <EOL> if i == len ( flow_kwargs ) - <NUM_LIT:1> : <EOL> flow_format += '<STR_LIT>' <EOL> else : <EOL> flow_format += '<STR_LIT:U+002CU+0020>' <EOL> i += <NUM_LIT:1> <EOL> txt += flow_format <EOL> txt += "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> txt = txt . format ( tot_frs_wrt , <EOL> pair_a , <EOL> pair_b , <EOL> btw_idx , <EOL> '<STR_LIT:Y>' if fr_type == '<STR_LIT:source>' else '<STR_LIT:N>' , <EOL> '<STR_LIT:Y>' if fr_type == '<STR_LIT>' else '<STR_LIT:N>' , <EOL> '<STR_LIT:Y>' if is_dup > <NUM_LIT:0> else '<STR_LIT:N>' , <EOL> hex ( id ( fr ) ) ) <EOL> for i , line in enumerate ( txt . split ( '<STR_LIT:\n>' ) ) : <EOL> line_sz , _ = cv2 . getTextSize ( line , <EOL> settings [ '<STR_LIT>' ] , <EOL> scale , <EOL> settings [ '<STR_LIT>' ] ) <EOL> _ , line_h = line_sz <EOL> origin = ( int ( settings [ '<STR_LIT>' ] ) , int ( settings [ '<STR_LIT>' ] + <EOL> ( i * ( line_h + settings [ '<STR_LIT>' ] ) ) ) ) <EOL> if text_type == '<STR_LIT>' : <EOL> draw_strk ( line , origin ) <EOL> draw_text ( line , origin ) <EOL> txt = "<STR_LIT>" "<STR_LIT>" <EOL> txt = txt . format ( sub_idx , <EOL> subs_to_render , <EOL> sub . fa , <EOL> sub . fb , <EOL> sub . ta / <NUM_LIT> , <EOL> sub . tb / <NUM_LIT> , <EOL> ( sub . fb - sub . fa ) + <NUM_LIT:1> , <EOL> ( sub . tb - sub . ta ) / <NUM_LIT> ) <EOL> def str_or_placeholder ( str_fmt , str ) : <EOL> if str is None : <EOL> return settings [ '<STR_LIT>' ] <EOL> return str_fmt . format ( str ) <EOL> txt += "<STR_LIT>" <EOL> txt = txt . format ( str_or_placeholder ( '<STR_LIT>' , sub . target_spd ) , <EOL> str_or_placeholder ( '<STR_LIT>' , sub . target_dur / <NUM_LIT> ) <EOL> if sub . target_dur else settings [ '<STR_LIT>' ] , <EOL> str_or_placeholder ( '<STR_LIT>' , sub . target_fps ) ) <EOL> txt += "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" "<STR_LIT>" <EOL> txt = txt . format ( tgt_frs , <EOL> tgt_frs / float ( rate ) , <EOL> drp_every , <EOL> dup_every , <EOL> src_seen , <EOL> frs_int , <EOL> frs_drp , <EOL> frs_dup , <EOL> frs_wrt , <EOL> tgt_frs , <EOL> frs_wrt * <NUM_LIT> / tgt_frs ) <EOL> for i , line in enumerate ( txt . split ( '<STR_LIT:\n>' ) ) : <EOL> line_sz , _ = cv2 . getTextSize ( line , <EOL> settings [ '<STR_LIT>' ] , <EOL> scale , <EOL> settings [ '<STR_LIT>' ] ) <EOL> line_w , line_h = line_sz <EOL> origin = ( int ( w - settings [ '<STR_LIT>' ] - line_w ) , <EOL> int ( settings [ '<STR_LIT>' ] + <EOL> ( i * ( line_h + settings [ '<STR_LIT>' ] ) ) ) ) <EOL> if text_type == '<STR_LIT>' : <EOL> draw_strk ( line , origin ) <EOL> draw_text ( line , origin ) </s>
