示例#1
0
def archive_img_pairs_w_flow_pyrs(img_pairs,
                                  dst_file,
                                  flow_pyrs=None,
                                  num_lvls=0,
                                  flow_preds=None,
                                  flow_gts=None,
                                  titles=None,
                                  info=None,
                                  flow_mag_max=None):
    """Plot and save to disk te given set of image pairs, optionally with flows and titles.
    Args:
        img_pairs: image pairs in [batch_size, 2, H, W, 3] or list([2, H, W, 3]) format.
        dst_file: Path where to save resulting image
        flow_pyrs: optional, predicted optical flow pyramids [batch_size, H, W, 2] or list([H, W, 2]) format.
        num_lvls: number of levels per pyramid (flow_pyrs must be set)
        flow_preds: optional, predicted flows in [batch_size, H, W, 2] or list([H, W, 2]) format.
        flow_gts: optional, groundtruth flows in [batch_size, H, W, 2] or list([H, W, 2]) format.
        titles: optional, list of image and flow IDs to display with each image.
        info: optional, stats to display above predicted flow
        flow_mag_max: Max flow to map to 255
    """
    # Create the output folder, if necessary
    # Empty the output folder of previous predictions, if any
    clean_dst_file(dst_file)

    # Build plot and save it to disk
    plt = plot_img_pairs_w_flows(img_pairs, flow_pyrs, num_lvls, flow_preds,
                                 flow_gts, titles, info, flow_mag_max)
    plt.savefig(dst_file, bbox_inches='tight', pad_inches=0.1)
    plt.close()
示例#2
0
def zmf_save_flows(names, flow_preds, addr):
    assert (len(names) == len(flow_preds))
    l = len(names)
    for i in range(l):
        dst = '%s/%s' % (addr, names[i])
        clean_dst_file(dst)
        flow_write(flow_preds[i], dst)
示例#3
0
def flow_write_as_png(flow, dst_file, info=None, flow_mag_max=None):
    """Write optical flow to a .PNG file
    Args:
        flow: optical flow
        dst_file: Path where to write optical flow as a .PNG file
        info: Text to superimpose on image (typically, the epe for the predicted flow)
        flow_mag_max: Max flow to map to 255
    """
    # Convert the optical flow field to RGB
    img = flow_to_img(flow, flow_mag_max=flow_mag_max)

    # Create the output folder, if necessary
    # Empty the output folder of previous predictions, if any
    clean_dst_file(dst_file)

    # Add text to the image, if requested
    if info is not None:
        font = cv2.FONT_HERSHEY_SIMPLEX
        cv2.putText(img, info, (20, 20), font, 0.8, (0, 0, 0), 2, cv2.LINE_AA)

    # Save RGB version of optical flow to disk
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        # imsave(dst_file, img)
        im = sp.misc.toimage(img, cmin=-1.0, cmax=1.0)
        im.save(dst_file)
示例#4
0
def flow_write(flow, dst_file):
    """Write optical flow to a .flo file
    Args:
        flow: optical flow
        dst_file: Path where to write optical flow
    """
    # Create the output folder, if necessary
    # Empty the output folder of previous predictions, if any
    clean_dst_file(dst_file)

    # Save optical flow to disk
    with open(dst_file, "wb") as f:
        np.array(TAG_FLOAT, dtype=np.float32).tofile(f)
        height, width = flow.shape[:2]
        np.array(width, dtype=np.uint32).tofile(f)
        np.array(height, dtype=np.uint32).tofile(f)
        flow.astype(np.float32).tofile(f)