def preset_color_epe(kwargs): # Flow directories flo_est_dir = get_arg(kwargs, 'flo_dir', lambda: ask_string( 'Estimated flow files directory ({s}): ', default='flo_est', is_path=True)) flo_gt_dir = get_arg(kwargs, 'flo_gt_dir', lambda: ask_string( 'Ground truth flow files directory ({s}): ', default='flo_gt', is_path=True)) # Flow normalization norm_type = get_arg(kwargs, 'norm_type', lambda: ask_multichoice('EPE normalization type ({s}): ', answer_map={'video': 'video', 'frame': 'frame', 'none': None}, default='frame')) if norm_type == 'video': clamp_pct = get_arg(kwargs, 'norm_clamp', lambda: float(ask_string( 'Normalization clamp percentage ({s}): ', default='1.0'))) gamma = get_arg(kwargs, 'norm_gamma', lambda: float(ask_string( 'Normalization gamma curve exponent ({s}): ', default='1.0'))) # Output options out_figure, out_options = ask_video_or_figure( kwargs, 'output_color_epe.mp4') # Generate EPE data flo_est = fv.input.flo(flo_est_dir) flo_gt = fv.input.flo(flo_gt_dir) epe_data = fv.endpoint_error(flo_est, flo_gt) # Normalize EPE data and convert to image if norm_type == 'frame': epe_data = fv.normalize_frame(epe_data) elif norm_type == 'video': epe_data = fv.normalize_video( epe_data, clamp_pct=clamp_pct, gamma=gamma, verbose=True) image_data = fv.epe_to_rgb(epe_data, color=[255, 255, 255]) # Generate output if out_figure: (framerate) = out_options out = fv.output.show_plot( title='color_epe result', framerate=framerate) out.show_all(image_data, show_count=True) else: (framerate, out_name) = out_options out = fv.output.video(out_name, framerate=framerate) out.add_all(image_data, verbose=True)
def preset_color_flow(kwargs): # Flow files flo_dir = get_arg(kwargs, 'flo_dir', lambda: ask_string('Flow files directory ({s}): ', default='flo', is_path=True)) # Flow normalization norm_type = get_arg(kwargs, 'norm_type', lambda: ask_multichoice('Vector normalization type ({s}): ', answer_map={'video': 'video', 'frame': 'frame', 'none': 'none'}, default='frame')) if norm_type == 'video': clamp_pct = get_arg(kwargs, 'norm_clamp', lambda: float(ask_string( 'Normalization clamp percentage ({s}): ', default='1.0'))) gamma = get_arg(kwargs, 'norm_gamma', lambda: float(ask_string( 'Normalization gamma curve exponent ({s}): ', default='1.0'))) # Output options out_figure, out_options = ask_video_or_figure( kwargs, 'output_color_flow.mp4') # Read flow data and normalize flo_data = fv.input.flo(flo_dir) if norm_type == 'frame': flo_data = fv.normalize_frame(flo_data) elif norm_type == 'video': flo_data = fv.normalize_video( flo_data, clamp_pct=clamp_pct, gamma=gamma, verbose=True) rgb_data = fv.flow_to_rgb(flo_data) # Generate output if out_figure: (framerate) = out_options out = fv.output.show_plot( title='color_flow result', framerate=framerate) out.show_all(rgb_data, show_count=True) else: (framerate, out_name) = out_options out = fv.output.video(out_name, framerate=framerate) out.add_all(rgb_data, verbose=True)
def preset_flow_arrows(kwargs): # Flow files and RGB frames of video flo_dir = get_arg( kwargs, 'flo_dir', lambda: ask_string( 'Flow files directory ({s}): ', default='flo', is_path=True)) # Background settings use_flow = get_arg( kwargs, 'use_flow_colors', lambda: ask_multichoice('Use flow colors for image? ({s}): ', answer_map={ 'y': True, 'n': False }, default='n')) if use_flow: arrow_color = (0, 0, 0) else: arrow_color = 'flow' rgb_dir = get_arg( kwargs, 'image_dir', lambda: ask_string( 'Image directory ({s}): ', default='png', is_path=True)) # Arrow subsampling subsample_ratio = get_arg( kwargs, 'subsample_ratio', lambda: float( ask_string('Flow subsample ratio ({s}): ', default='16.0'))) # Output options out_figure, out_options = ask_video_or_figure(kwargs, 'output_flow_arrows.mp4') # Add points and generate image flo_data = fv.input.flo(flo_dir) if use_flow: flo_data_norm = fv.normalize_frame(flo_data) rgb_data = fv.flow_to_rgb(flo_data_norm) background_attenuation = 0.0 flat_colors = True arrow_color = (0, 0, 0) else: rgb_data = fv.input.rgb(rgb_dir) background_attenuation = 0.4 flat_colors = False arrow_color = 'flow' arrow_data = fv.draw_flow_arrows( rgb_data, flo_data, background_attenuation=background_attenuation, color=arrow_color, flat_colors=flat_colors, arrow_min_alpha=0.7, subsample_ratio=subsample_ratio, ignore_ratio_warning=False) # Generate output if out_figure: (framerate) = out_options out = fv.output.show_plot(title='color_flow result', framerate=framerate) out.show_all(arrow_data, show_count=True) else: (framerate, out_name) = out_options out = fv.output.video(out_name, framerate=framerate) out.add_all(arrow_data, verbose=True)