Пример #1
0
    for name in os.listdir(args.test_list):

        print('processing {}'.format(name))
        path = []
        right = os.path.join('data/flow_dataset/ceshi/right', name)
        path.append(os.path.join(args.test_list, name))
        path.append(right)
        imgs = [imageio.imread(img).astype(np.float32) for img in path]
        h, w = imgs[0].shape[:2]

        res_dict = ts.run(imgs)
        flow_12 = res_dict['flows_fw'][0]
        flow_21 = res_dict['flows_bw'][0]

        flow_12 = resize_flow(flow_12, (h, w))  # [1, 2, H, W]
        flow_21 = resize_flow(flow_21, (h, w))  # [1, 2, H, W]
        occu_mask1 = 1 - get_occu_mask_bidirection(flow_12,
                                                   flow_21)  # [1, 1, H, W]
        occu_mask2 = 1 - get_occu_mask_bidirection(flow_21, flow_12)
        back_occu_mask1 = get_occu_mask_backward(flow_21)
        back_occu_mask2 = get_occu_mask_backward(flow_21)

        warped_image_12 = flow_warp(torch.from_numpy(
            np.transpose(imgs[1], [2, 0, 1])).unsqueeze(0).cuda(),
                                    flow_12,
                                    pad='border')
        warped_image_21 = flow_warp(torch.from_numpy(
            np.transpose(imgs[0], [2, 0, 1])).unsqueeze(0).cuda(),
                                    flow_21,
                                    pad='border')
Пример #2
0
        'test_shape': args.test_shape,
    }

    t3 = args.img_list[0].split('_')
    t0 = t3[2].split('.')
    t = args.img_list[1].split('_')
    t1 = t[2].split('.')

    ts = TestHelper(cfg)

    imgs = [imageio.imread(img).astype(np.float32) for img in args.img_list]
    h, w = imgs[0].shape[:2]

    flow_12 = ts.run(imgs)['flows_fw'][0]

    flow_12 = resize_flow(flow_12, (h, w))
    np_flow_12 = flow_12[0].detach().cpu().numpy().transpose([1, 2, 0])

    vis_flow = flowpy.flow_to_rgb(np_flow_12)

    cv2.imwrite(t0[0] + " " + t1[0] + ".png", vis_flow)

    #=flow_warp(im2, flow12, pad='border', mode='bilinear'):
    first_image = np.asarray(Image.open(args.img_list[0]))
    cv2.imwrite(t0[0] + ".png", first_image)
    second_image = np.asarray(Image.open(args.img_list[1]))

    np_flow_12[np.isnan(np_flow_12)] = 0
    warped_first_image = flowpy.backward_warp(second_image, np_flow_12)

    cv2.imwrite("warped_oc" + t1[0] + ".png", warped_first_image)
Пример #3
0
            'reduce_dense': True
        },
        'pretrained_model': args.model,
        'test_shape': args.test_shape,
    }

    ts = TestHelper(cfg)
    if args.show:
        imgs = [
            imageio.imread(img).astype(np.float32) for img in args.img_list
        ]
        h, w = imgs[0].shape[:2]

        flow_12 = ts.run(imgs)['flows_fw'][0]

        flow_12 = resize_flow(flow_12, (h, w))
        np_flow_12 = flow_12[0].detach().cpu().numpy().transpose([1, 2, 0])

        vis_flow = flow_to_image(np_flow_12)

        fig = plt.figure()
        plt.imshow(vis_flow)
        plt.show()
    else:
        root = args.root + '/{}'.format(args.root_split)
        classes = [
            d for d in os.listdir(root) if os.path.isdir(os.path.join(root, d))
        ]
        classes.sort()
        class_to_idx = {classes[i]: i for i in range(len(classes))}