示例#1
0
    def __getitem__(self, idx):
        result = {}

        left_fname = self.left_data[idx]
        result['left'] = np.array(Image.open(left_fname)).astype(
            np.uint8)[..., :3]

        right_fname = left_fname.replace('left', 'right')
        result['right'] = np.array(Image.open(right_fname)).astype(
            np.uint8)[..., :3]

        disp_left_fname = left_fname.replace('frames_cleanpass',
                                             'disparity').replace(
                                                 '.png', '.pfm')
        disp_right_fname = right_fname.replace('frames_cleanpass',
                                               'disparity').replace(
                                                   '.png', '.pfm')
        disp_left, _ = readPFM(disp_left_fname)
        disp_right, _ = readPFM(disp_right_fname)

        occ_left_fname = left_fname.replace('frames_cleanpass', 'occlusion')
        occ_right_fname = right_fname.replace('frames_cleanpass', 'occlusion')
        occ_left = np.array(Image.open(occ_left_fname)).astype(np.bool)
        occ_right = np.array(Image.open(occ_right_fname)).astype(np.bool)

        result['occ_mask'] = occ_left
        result['occ_mask_right'] = occ_right
        result['disp'] = disp_left
        result['disp_right'] = disp_right

        result = augment(result, self.transformation)

        return result
    def __getitem__(self, idx):
        input_data = {}

        path = self.datadir

        left = np.array(Image.open(os.path.join(path, self.left_fold, self.data[idx]))).astype(np.uint8)[..., :3]
        input_data['left'] = left

        right = np.array(Image.open(os.path.join(path, self.right_fold, self.data[idx]))).astype(np.uint8)[..., :3]
        input_data['right'] = right

        occ = np.array(Image.open(os.path.join(path, self.occ_fold, self.data[idx]))).astype(np.bool)
        input_data['occ_mask'] = occ

        occ_right = np.array(Image.open(os.path.join(path, self.occ_fold_right, self.data[idx]))).astype(np.bool)
        input_data['occ_mask_right'] = occ_right

        disp, _ = readPFM(os.path.join(path, self.disp, self.data[idx].replace('png', 'pfm')))
        input_data['disp'] = disp

        disp_right, _ = readPFM(os.path.join(path, self.disp_right, self.data[idx].replace('png', 'pfm')))
        input_data['disp_right'] = disp_right

        input_data = augment(input_data, self.transformation)

        return input_data
示例#3
0
    def __getitem__(self, idx):
        input_data = {}

        # left
        left_fname = os.path.join(self.datadir, self.left_data[idx])
        left = np.array(Image.open(left_fname)).astype(np.uint8)
        input_data['left'] = left

        # right
        right_fname = os.path.join(self.datadir, self.right_data[idx])
        right = np.array(Image.open(right_fname)).astype(np.uint8)
        input_data['right'] = right

        if not self.split == 'test':  # no disp for test files
            # occ
            occ_left_fname = os.path.join(self.datadir,
                                          self.occ_left_data[idx])
            occ_right_fname = os.path.join(self.datadir,
                                           self.occ_right_data[idx])
            occ_left = np.array(Image.open(occ_left_fname)) == 128
            occ_right = np.array(Image.open(occ_right_fname)) == 128

            # disp
            disp_left_fname = os.path.join(self.datadir,
                                           self.disp_left_data[idx])
            disp_right_fname = os.path.join(self.datadir,
                                            self.disp_right_data[idx])

            disp_left, _ = readPFM(disp_left_fname)
            disp_right, _ = readPFM(disp_right_fname)

            if self.split == 'train':
                # horizontal flip
                input_data['left'], input_data['right'], input_data['occ_mask'], input_data['occ_mask_right'], \
                input_data['disp'], \
                input_data['disp_right'] = horizontal_flip(input_data['left'], input_data['right'], occ_left, occ_right,
                                                           disp_left,
                                                           disp_right, self.split)
                # random crop
                input_data = random_crop(360, 640, input_data, self.split)
            else:
                input_data['occ_mask'] = occ_left
                input_data['occ_mask_right'] = occ_right
                input_data['disp'] = disp_left
                input_data['disp_right'] = disp_right
            input_data = augment(input_data, self.transformation)
        else:
            input_data = normalization(**input_data)

        return input_data
示例#4
0
    def __getitem__(self, idx):
        result = {}

        left_fname = self.left_data[idx]
        result['left'] = np.array(Image.open(left_fname)).astype(
            np.uint8)[..., :3]

        right_fname = left_fname.replace('left', 'right')
        result['right'] = np.array(Image.open(right_fname)).astype(
            np.uint8)[..., :3]

        occ_right_fname = self.occ_data[idx].replace('left', 'right')
        occ_left = np.array(Image.open(self.occ_data[idx])).astype(np.bool)
        occ_right = np.array(Image.open(occ_right_fname)).astype(np.bool)

        disp_left_fname = left_fname.replace('frame_finalpass',
                                             'disparity').replace(
                                                 '.png', '.pfm')
        disp_right_fname = right_fname.replace('frame_finalpass',
                                               'disparity').replace(
                                                   '.png', '.pfm')
        disp_left, _ = readPFM(disp_left_fname)
        disp_right, _ = readPFM(disp_right_fname)

        if self.split == "train":
            # horizontal flip
            result['left'], result['right'], result['occ_mask'], result['occ_mask_right'], disp, disp_right \
                = horizontal_flip(result['left'], result['right'], occ_left, occ_right, disp_left, disp_right,
                                  self.split)
            result['disp'] = np.nan_to_num(disp, nan=0.0)
            result['disp_right'] = np.nan_to_num(disp_right, nan=0.0)

            # random crop
            result = random_crop(360, 640, result, self.split)
        else:
            result['occ_mask'] = occ_left
            result['occ_mask_right'] = occ_right
            result['disp'] = disp_left
            result['disp_right'] = disp_right

        result = augment(result, self.transformation)

        return result
示例#5
0
    def __getitem__(self, idx):
        result = {}

        left_fname = self.left_data[idx]
        result['left'] = np.array(Image.open(left_fname)).astype(np.uint8)

        right_fname = left_fname.replace('img_left', 'img_right')
        result['right'] = np.array(Image.open(right_fname)).astype(np.uint8)

        disp_fname = left_fname.replace('img_left', 'disp_left').replace('.png', '.pfm')
        disp, _ = readPFM(disp_fname)
        result['disp'] = disp

        occ_fname = left_fname.replace('img_left', 'occ_left')
        result['occ_mask'] = np.array(Image.open(occ_fname)).astype(np.uint8) == 128
        result['disp'][result['occ_mask']] = 0.0

        result = augment(result, self.transformation)

        return result
示例#6
0
    def __getitem__(self, idx):
        result = {}

        left_fname = self.left_data[idx]
        result['left'] = np.array(Image.open(left_fname)).astype(
            np.uint8)[..., :3]

        right_fname = left_fname.replace('left', 'right')
        result['right'] = np.array(Image.open(right_fname)).astype(
            np.uint8)[..., :3]

        occ_left_fname = left_fname.replace("image_clean",
                                            "disparity_occlusions")
        occ_right_fname = right_fname.replace("image_clean",
                                              "disparity_occlusions")

        #occ_right_fname = self.occ_data[idx].replace('left', 'right')
        occ_left = np.array(Image.open(occ_left_fname)).astype(np.bool)
        occ_right = np.array(Image.open(occ_right_fname)).astype(np.bool)

        disp_left_fname = left_fname.replace('image_clean',
                                             'disparity').replace(
                                                 '.png', '.pfm')
        disp_right_fname = right_fname.replace('image_clean',
                                               'disparity').replace(
                                                   '.png', '.pfm')
        disp_left, _ = readPFM(disp_left_fname)
        disp_right, _ = readPFM(disp_right_fname)

        imgleft = np.array(result["left"])
        np.save("./leftimg", imgleft)

        disp_out = np.array(disp_left)
        np.save("./displeft_out", disp_out)

        disp_outr = np.array(disp_right)
        np.save("./dispright_out", disp_outr)

        occleft = np.array(occ_left)
        np.save("./occleft", occleft)

        occright = np.array(occ_right)
        np.save("./occright", occright)

        if self.split == "train":
            # horizontal flip
            #result['left'], result['right'], result['occ_mask'], result['occ_mask_right'], disp, disp_right \
            #    = horizontal_flip(result['left'], result['right'], occ_left, occ_right, disp_left, disp_right, self.split)

            result['left'], result['right'], result['occ_mask'], result['occ_mask_right'], disp, disp_right \
                =result['left'], result['right'], occ_left, occ_right, disp_left, disp_right

            result['disp'] = np.nan_to_num(disp, nan=0.0)
            result['disp_right'] = np.nan_to_num(disp_right, nan=0.0)

            # random crop
            result = random_crop(360, 640, result, self.split)
        else:
            result['occ_mask'] = occ_left
            result['occ_mask_right'] = occ_right
            result['disp'] = disp_left
            result['disp_right'] = disp_right

        result = augment(result, self.transformation)
        #cc=result["disp"]
        return result