Exemplo n.º 1
0
def gen_mpis(basedir, savedir, fwh, logdir, num_planes, no_mpis, disps, psvs):
    if not os.path.exists(savedir):
        os.makedirs(savedir)

    # load up images, poses, w/ scale factor
    poses, bds, imgs = load_data(basedir, *fwh)

    # load up model
    ibr_runner = DeepIBR()
    ibr_runner.load_graph(logdir)

    patched = imgs.shape[0] * imgs.shape[1] * num_planes > 640 * 480 * 32

    N = imgs.shape[-1]
    close_depths = [bds.min() * .9] * N
    inf_depths = [bds.max() * 2.] * N
    mpi_bds = np.array([close_depths, inf_depths])

    mpis = run_inference(imgs,
                         poses,
                         mpi_bds,
                         ibr_runner,
                         num_planes,
                         patched,
                         disps=disps,
                         psvs=psvs)

    for i in range(N):
        if not os.path.exists('{}/mpi{:02d}'.format(savedir, i)):
            os.makedirs('{}/mpi{:02d}'.format(savedir, i))
        if not no_mpis:
            mpis[i].save('{}/mpi{:02d}'.format(savedir, i), False, True)
        if disps:
            plt.imsave(os.path.join(savedir, 'mpi{:02d}/disps.png'.format(i)),
                       mpis[i].disps)
        if psvs:
            psv = np.moveaxis(mpis[i].psv, -2, 0)
            psv = (255 * np.clip(psv, 0, 1)).astype(np.uint8)
            imageio.mimwrite(os.path.join(savedir,
                                          'mpi{:02d}/psv.mp4'.format(i)),
                             psv,
                             fps=30,
                             quality=5)

    with open(os.path.join(savedir, 'metadata.txt'), 'w') as file:
        file.write('{} {} {} {}\n'.format(N, imgs.shape[1], imgs.shape[0],
                                          num_planes))

    print('Saved to', savedir)
    return True
Exemplo n.º 2
0
    args.y_axis,
    args.z_axis,
    args.circle,
    args.spiral,
    args.cylinder_1,
    args.cylinder_1_5,
    args.cylinder_2,
    args.grid_1,
    args.grid_1_5,
    args.grid_2
]
if any(comps) is False:
    comps = [True] * 11
print('Path components', comps)

poses, bds = load_data(args.scenedir, load_imgs=False)

render_poses = generate_render_path(poses, bds, comps, N=30, scenedir=args.scenedir)

if args.outname.endswith('txt'):
    
    render_poses = np.concatenate([render_poses[...,1:2], 
                                  -render_poses[...,0:1], 
                                   render_poses[...,2:]], -1)
    
    str_out = '{}\n'.format(render_poses.shape[0])
    for p in render_poses:
        str_out += ' '.join(['{}'.format(x) for x in p.T.ravel()]) + '\n'
    open(args.outname, 'w').write(str_out)
    
elif args.outname.endswith('npy'):