예제 #1
0
    def __getitem__(self, idx):
        imgnames = self.lines[idx].split(' ')
        dispImg, scale0 = readPFM(imgnames[2].strip())
        (imgHeight, imgWidth) = dispImg.shape
        # resize the images
        dispImg = cv2.resize(
            dispImg, (int(imgWidth / self.scale), int(imgHeight / self.scale)))
        dispImg = dispImg[:, :, np.newaxis]
        dispImg = dispImg / self.scale  # shrink the disparity due to the shrink of the image size

        # read two image files
        leftImg = cv2.imread(imgnames[0].strip())
        rightImg = cv2.imread(imgnames[1].strip())
        leftImg = cv2.resize(
            leftImg, (int(imgWidth / self.scale), int(imgHeight / self.scale)))
        rightImg = cv2.resize(
            rightImg,
            (int(imgWidth / self.scale), int(imgHeight / self.scale)))
        # leftImg = leftImg - self.mean # mean substraction
        # rightImg = rightImg - self.mean

        sample = {'left': leftImg, 'right': rightImg, 'disp': dispImg}

        if self.transform:
            sample = self.transform(sample)

        return sample
def read_pfm_file(flow_file):
    """
    Read from .pfm file
    :param flow_file: name of the flow file
    :return: optical flow data in matrix
    """
    import pfm
    (data, scale) = pfm.readPFM(flow_file)
    return data
예제 #3
0
def read_pfm_file(flow_file):
    """
    Read from .pfm file
    :param flow_file: name of the flow file
    :return: optical flow data in matrix
    """
    from . import pfm
    (data, scale) = pfm.readPFM(flow_file)
    return data
예제 #4
0
def main(args):

    left_image = io.imread(os.path.join(args.dirname, "im0.png")).astype(np.float32) / ((1 << 8) -1)
    right_image = io.imread(os.path.join(args.dirname, "im1.png")).astype(np.float32) / ((1 << 8) -1)
    left_disparity = pfm.readPFM(os.path.join(args.dirname, "disp0GT.pfm"))[0].astype(np.float32)[..., np.newaxis]
    right_disparity = pfm.readPFM(os.path.join(args.dirname, "disp1GT.pfm"))[0].astype(np.float32)[..., np.newaxis]
    left_occlusion = io.imread(os.path.join(args.dirname, "mask0nocc.png")).astype(np.float32)[..., np.newaxis] / ((1 << 8) -1)
    right_occlusion = io.imread(os.path.join(args.dirname, "mask1nocc.png")).astype(np.float32)[..., np.newaxis] / ((1 << 8) -1)

    left_image = torch.from_numpy(left_image).permute(2, 0, 1).unsqueeze(0)
    right_image = torch.from_numpy(right_image).permute(2, 0, 1).unsqueeze(0)
    left_disparity = torch.from_numpy(left_disparity).permute(2, 0, 1).unsqueeze(0)
    right_disparity = torch.from_numpy(right_disparity).permute(2, 0, 1).unsqueeze(0)
    left_occlusion = torch.from_numpy(left_occlusion).permute(2, 0, 1).unsqueeze(0)
    right_occlusion = torch.from_numpy(right_occlusion).permute(2, 0, 1).unsqueeze(0)
    
    left_disparity = torch.where(torch.isfinite(left_disparity), left_disparity, torch.zeros_like(left_disparity))
    right_disparity = torch.where(torch.isfinite(right_disparity), right_disparity, torch.zeros_like(right_disparity))

    left_occlusion = torch.where(left_occlusion < 1, torch.zeros_like(left_occlusion), left_occlusion)
    right_occlusion = torch.where(right_occlusion < 1, torch.zeros_like(right_occlusion), right_occlusion)

    backward_left_image = warping.warp_backward(right_image, left_disparity, invert=True) * left_occlusion
    backward_right_image = warping.warp_backward(left_image, right_disparity, invert=False) * right_occlusion

    forward_left_image = warping.warp_forward(right_image, right_disparity, right_occlusion, invert=False)
    forward_right_image = warping.warp_forward(left_image, left_disparity, left_occlusion, invert=True)

    backward_left_image = backward_left_image.squeeze(0).permute(1, 2, 0).numpy()
    backward_right_image = backward_right_image.squeeze(0).permute(1, 2, 0).numpy()

    forward_left_image = forward_left_image.squeeze(0).permute(1, 2, 0).numpy()
    forward_right_image = forward_right_image.squeeze(0).permute(1, 2, 0).numpy()

    io.imsave("backward0.png", backward_left_image)
    io.imsave("backward1.png", backward_right_image)
    io.imsave("forward0.png", forward_left_image)
    io.imsave("forward1.png", forward_right_image)
def pfm_to_flo(pfm_file):
    flow_filename = pfm_file[0:pfm_file.find('.pfm')] + '.flo'
    (data, scale) = pfm.readPFM(pfm_file)
    flow = data[:, :, 0:2]
    write_flow(flow, flow_filename)
예제 #6
0
def pfm_to_flo(pfm_file):
    flow_filename = pfm_file[0:pfm_file.find('.pfm')] + '.flo'
    (data, scale) = pfm.readPFM(pfm_file)
    flow = data[:, :, 0:2]
    write_flow(flow, flow_filename)
예제 #7
0
 def read_disp_pfm(disp_file):
     import pfm
     (data, scale) = pfm.readPFM(disp_file)
     return data
예제 #8
0
def read_pfm(flow_file):
    import pfm
    (data, scale) = pfm.readPFM(flow_file)
    return data