Ejemplo n.º 1
0
    def __getitem__(self, index):
        tgt_img_path = self.root.joinpath(self.phase, 'colored_0',
                                          str(index).zfill(6) + '_10.png')
        ref_img_paths = [
            self.root.joinpath(
                self.phase, 'colored_0',
                str(index).zfill(6) + '_' + str(k).zfill(2) + '.png')
            for k in self.seq_ids
        ]
        gt_flow_path_occ = self.root.joinpath(self.phase, 'flow_occ',
                                              str(index).zfill(6) + '_10.png')
        gt_flow_path_noc = self.root.joinpath(self.phase, 'flow_noc',
                                              str(index).zfill(6) + '_10.png')

        tgt_img = load_as_float(tgt_img_path)
        ref_imgs = [load_as_float(ref_img) for ref_img in ref_img_paths]

        u_occ, v_occ, valid_occ = flow_io.flow_read_png(gt_flow_path_occ)
        gtFlow_occ = np.dstack((u_occ, v_occ, valid_occ))
        gtFlow_occ = torch.FloatTensor(gtFlow_occ.transpose(2, 0, 1))

        u_noc, v_noc, valid_noc = flow_io.flow_read_png(gt_flow_path_noc)
        gtFlow_noc = np.dstack((u_noc, v_noc, valid_noc))
        gtFlow_noc = torch.FloatTensor(gtFlow_noc.transpose(2, 0, 1))

        if self.transform is not None:
            imgs = self.transform([tgt_img] + ref_imgs)
            tgt_img = imgs[0]
            ref_imgs = imgs[1:]

        return tgt_img, ref_imgs, gtFlow_occ, gtFlow_noc
Ejemplo n.º 2
0
    def __getitem__(self, index):
        tgt_img_path = self.root.joinpath('data_stereo_flow', self.phase,
                                          'colored_0',
                                          str(index).zfill(6) + '_10.png')
        ref_img_path = self.root.joinpath('data_stereo_flow', self.phase,
                                          'colored_0',
                                          str(index).zfill(6) + '_11.png')
        gt_flow_path = self.root.joinpath('data_stereo_flow', self.phase,
                                          'flow_occ',
                                          str(index).zfill(6) + '_10.png')

        tgt_img = load_as_float(tgt_img_path)
        ref_img = load_as_float(ref_img_path)

        u, v, valid = flow_io.flow_read_png(gt_flow_path)
        #gtFlow = scale_flow(np.dstack((u,v,valid)), h=self.flow_h, w=self.flow_w)
        gtFlow = np.dstack((u, v, valid))
        gtFlow = torch.FloatTensor(gtFlow.transpose(2, 0, 1))

        intrinsics = np.eye(3)
        if self.transform is not None:
            imgs, intrinsics = self.transform([tgt_img] + [ref_img],
                                              np.copy(intrinsics))
            tgt_img = imgs[0]
            ref_img = imgs[1]
        else:
            intrinsics = np.copy(intrinsics)
        return tgt_img, ref_img, intrinsics, np.linalg.inv(intrinsics), gtFlow
Ejemplo n.º 3
0
    def __getitem__(self, index):
        tgt_img_path = self.root.joinpath('data_scene_flow_multiview',
                                          self.phase, 'image_2',
                                          str(index).zfill(6) + '_10.png')
        ref_img_paths = [
            self.root.joinpath(
                'data_scene_flow_multiview', self.phase, 'image_2',
                str(index).zfill(6) + '_' + str(k).zfill(2) + '.png')
            for k in self.seq_ids
        ]
        gt_flow_path = self.root.joinpath('data_scene_flow', self.phase,
                                          self.occ,
                                          str(index).zfill(6) + '_10.png')

        tgt_img = load_as_float(tgt_img_path)
        ref_imgs = [load_as_float(ref_img) for ref_img in ref_img_paths]

        u_occ, v_occ, valid_occ = flow_io.flow_read_png(gt_flow_path)
        gtFlow = np.dstack((u_occ, v_occ, valid_occ))
        gtFlow = torch.FloatTensor(gtFlow.transpose(2, 0, 1))

        if self.transform is not None:
            imgs = self.transform([tgt_img] + ref_imgs)
            tgt_img = imgs[0]
            ref_imgs = imgs[1:]

        return tgt_img, ref_imgs, gtFlow
Ejemplo n.º 4
0
    def __getitem__(self, index):
        tgt_img_path =  self.root.joinpath('data_scene_flow_multiview', self.phase, 'image_2',str(index).zfill(6)+'_10.png')
        ref_img_paths = [self.root.joinpath('data_scene_flow_multiview', self.phase, 'image_2',str(index).zfill(6)+'_'+str(k).zfill(2)+'.png') for k in self.seq_ids]
        gt_flow_path = self.root.joinpath('data_scene_flow', self.phase, 'flow_occ', str(index).zfill(6)+'_10.png')
        cam_calib_path = self.root.joinpath('data_scene_flow_calib', self.phase, 'calib_cam_to_cam', str(index).zfill(6)+'.txt')
        obj_map_path = self.root.joinpath('data_scene_flow', self.phase, 'obj_map', str(index).zfill(6)+'_10.png')
        semantic_map_path = self.root.joinpath('semantic_labels', self.phase, 'semantic', str(index).zfill(6)+'_10.png')

        tgt_img = load_as_float(tgt_img_path)
        ref_imgs = [load_as_float(ref_img) for ref_img in ref_img_paths]
        obj_map = torch.LongTensor(np.array(Image.open(obj_map_path)))
        semantic_map = torch.LongTensor(np.array(Image.open(semantic_map_path)))
        u,v,valid = flow_io.flow_read_png(gt_flow_path)
        gtFlow = np.dstack((u,v,valid))
        #gtFlow = scale_flow(np.dstack((u,v,valid)), h=self.flow_h, w=self.flow_w)
        gtFlow = torch.FloatTensor(gtFlow.transpose(2,0,1))
        intrinsics = get_intrinsics(cam_calib_path).astype('float32')

        if self.transform is not None:
            imgs, intrinsics = self.transform([tgt_img] + ref_imgs, np.copy(intrinsics))
            tgt_img = imgs[0]
            ref_imgs = imgs[1:]
        else:
            intrinsics = np.copy(intrinsics)
        return tgt_img, ref_imgs, intrinsics, np.linalg.inv(intrinsics), gtFlow, obj_map, semantic_map
Ejemplo n.º 5
0
    def __getitem__(self, index):
        tgt_img_path =  self.root.joinpath('data_scene_flow_multiview', self.phase, 'image_3',str(index).zfill(6)+'_10.png')
        ref_img_paths = [self.root.joinpath('data_scene_flow_multiview', self.phase, 'image_3',str(index).zfill(6)+'_'+str(k).zfill(2)+'.png') for k in self.seq_ids]
        gt_flow_path = self.root.joinpath('data_scene_flow', self.phase, self.occ, str(index).zfill(6)+'_10.png')
        cam_calib_path = self.root.joinpath('data_scene_flow_calib', self.phase, 'calib_cam_to_cam', str(index).zfill(6)+'.txt')
        obj_map_path = self.root.joinpath('data_scene_flow', self.phase, 'obj_map', str(index).zfill(6)+'_10.png')

        tgt_img = load_as_float(tgt_img_path)
        # for x in self.seq_ids:
        #     print(x)
        # for ref_img in ref_img_paths:
        #     if ref_img:
        #         load_as_float(ref_img)
        # exit()
        ref_imgs = [load_as_float(ref_img) for ref_img in ref_img_paths]
        if os.path.isfile(obj_map_path):
            obj_map = load_as_float(obj_map_path)
        else:
            obj_map = np.ones((tgt_img.shape[0], tgt_img.shape[1]))
        u,v,valid = flow_io.flow_read_png(gt_flow_path)
        gtFlow = np.dstack((u,v,valid))
        #gtFlow = scale_flow(np.dstack((u,v,valid)), h=self.flow_h, w=self.flow_w)
        gtFlow = torch.FloatTensor(gtFlow.transpose(2,0,1))
        intrinsics = get_intrinsics(cam_calib_path).astype('float32')

        if self.transform is not None:
            imgs, intrinsics = self.transform([tgt_img] + ref_imgs, np.copy(intrinsics))
            tgt_img = imgs[0]
            ref_imgs = imgs[1:]
        else:
            intrinsics = np.copy(intrinsics)
        return tgt_img, ref_imgs, intrinsics, np.linalg.inv(intrinsics), gtFlow, obj_map
Ejemplo n.º 6
0
    def __getitem__(self, index):
        index = self.start + index
        scene = index // 20
        frame = index % 20

        tgt_img_path = self.root.joinpath(
            'data_scene_flow_multiview', self.phase, 'image_2',
            str(scene).zfill(6) + '_' + str(frame).zfill(2) + '.png')
        ref_img_past_path = self.root.joinpath(
            'data_scene_flow_multiview', self.phase, 'image_2',
            str(scene).zfill(6) + '_' + str(frame - 1).zfill(2) + '.png')
        ref_img_future_path = self.root.joinpath(
            'data_scene_flow_multiview', self.phase, 'image_2',
            str(scene).zfill(6) + '_' + str(frame + 1).zfill(2) + '.png')
        gt_flow_path = self.root.joinpath(
            'data_scene_flow', self.phase, 'flow_occ',
            str(scene).zfill(6) + '_' + str(frame).zfill(2) + '.png')
        gt_disp_path = self.root.joinpath(
            'data_scene_flow', self.phase, 'disp_occ_0',
            str(scene).zfill(6) + '_' + str(frame).zfill(2) + '.png')

        tgt_img = load_as_float(tgt_img_path)
        ref_img_future = load_as_float(ref_img_future_path)
        if os.path.exists(gt_flow_path):
            ref_img_past = load_as_float(ref_img_past_path)
        else:
            ref_img_past = torch.zeros(tgt_img.shape)

        he, wi, ch = tgt_img.shape

        gtFlow = None
        if os.path.exists(gt_flow_path):
            u, v, valid = flow_io.flow_read_png(str(gt_flow_path))
            gtFlow = np.dstack((u, v, valid))
            gtFlow = torch.FloatTensor(gtFlow.transpose(2, 0, 1))
        else:
            gtFlow = torch.zeros((3, he, wi))

        # read disparity
        gtDisp = None
        if os.path.exists(gt_flow_path):
            gtDisp = load_as_float(gt_disp_path)
            gtDisp = np.array(gtDisp, dtype=float) / 256.
        else:
            gtDisp = torch.zeros((he, wi, 1))

        calib = {}
        poses = {}

        if self.transform is not None:
            in_h, in_w, _ = tgt_img.shape
            imgs = self.transform([tgt_img] + [ref_img_past] +
                                  [ref_img_future])
            tgt_img = imgs[0]
            ref_img_past = imgs[1]
            ref_img_future = imgs[2]
            _, out_h, out_w = tgt_img.shape

        return ref_img_past, tgt_img, ref_img_future, gtFlow, gtDisp, calib, poses
Ejemplo n.º 7
0
def main():
    global args
    args = parser.parse_args()

    args.output_dir = Path(args.output_dir)
    args.gt_dir = Path(args.gt_dir)

    error_names = ['epe_total', 'outliers']
    errors = AverageMeter(i=len(error_names))

    for i in tqdm(range(args.N)):
        gt_flow_path = args.gt_dir.joinpath(str(i).zfill(6) + '_10.png')
        output_flow_path = args.output_dir.joinpath(
            str(i).zfill(6) + '_10.png')
        u_gt, v_gt, valid_gt = flow_io.flow_read_png(gt_flow_path)
        u_pred, v_pred, valid_pred = flow_io.flow_read_png(output_flow_path)

        _errors = compute_err(u_gt, v_gt, valid_gt, u_pred, v_pred, valid_pred)
        errors.update(_errors)

    print("Results")
    print("\t {:>10}, {:>10} ".format(*error_names))
    print("Errors \t {:10.4f}, {:10.4f}".format(*errors.avg))
Ejemplo n.º 8
0
    def __getitem__(self, index):
        tgt_img_path = self.root.joinpath('data_stereo_flow', self.phase,
                                          'colored_0',
                                          str(index).zfill(6) + '_10.png')
        ref_img_past_path = self.root.joinpath('data_stereo_flow', self.phase,
                                               'colored_0',
                                               str(index).zfill(6) + '_11.png')
        ref_img_future_path = self.root.joinpath(
            'data_stereo_flow', self.phase, 'colored_0',
            str(index).zfill(6) + '_11.png')
        gt_flow_path = self.root.joinpath('data_stereo_flow', self.phase,
                                          'flow_occ',
                                          str(index).zfill(6) + '_10.png')

        tgt_img = load_as_float(tgt_img_path)
        ref_img_past = load_as_float(ref_img_past_path)
        ref_img_future = load_as_float(ref_img_future_path)

        u, v, valid = flow_io.flow_read_png(gt_flow_path)
        gtFlow = np.dstack((u, v, valid))
        gtFlow = torch.FloatTensor(gtFlow.transpose(2, 0, 1))

        if self.transform is not None:
            imgs = self.transform([tgt_img] + [ref_img_past] +
                                  [ref_img_future])
            tgt_img = imgs[0]
            ref_img_past = imgs[1]
            ref_img_future = imgs[2]

        #if self.compression is not None:
        #    encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), self.compression]
        #    ref_img_past = cv2.imencode('.jpg', ref_img_past, encode_param)
        #    tgt_img = cv2.imencode('.jpg', tgt_img, encode_param)
        #    ref_img_future = cv2.imencode('.jpg', ref_img_future, encode_param)

        return ref_img_past, tgt_img, ref_img_future, gtFlow, None, None,
Ejemplo n.º 9
0
    def __getitem__(self, index):
        index = self.start + index

        tgt_img_path = self.root.joinpath('data_scene_flow_multiview',
                                          self.phase, 'image_2',
                                          str(index).zfill(6) + '_10.png')
        ref_img_past_path = self.root.joinpath('data_scene_flow_multiview',
                                               self.phase, 'image_2',
                                               str(index).zfill(6) + '_09.png')
        ref_img_future_path = self.root.joinpath(
            'data_scene_flow_multiview', self.phase, 'image_2',
            str(index).zfill(6) + '_11.png')
        gt_flow_path = self.root.joinpath('data_scene_flow', self.phase,
                                          'flow_occ',
                                          str(index).zfill(6) + '_10.png')
        gt_disp_path = self.root.joinpath('data_scene_flow', self.phase,
                                          'disp_occ_0',
                                          str(index).zfill(6) + '_10.png')

        tgt_img = load_as_float(tgt_img_path)
        ref_img_past = load_as_float(ref_img_past_path)
        ref_img_future = load_as_float(ref_img_future_path)
        u, v, valid = flow_io.flow_read_png(str(gt_flow_path))
        gtFlow = np.dstack((u, v, valid))
        gtFlow = torch.FloatTensor(gtFlow.transpose(2, 0, 1))

        # read disparity
        gtDisp = load_as_float(gt_disp_path)
        gtDisp = np.array(gtDisp, dtype=float) / 256.
        calib = {}
        poses = {}
        # get calibrations
        if self.mapping[index] is not None:
            path = os.path.join(self.raw_root, self.mapping[index]['Scene'])
            seq = self.mapping[index]['Sequence'][
                len(self.mapping[index]['Scene'] + '_drive') + 1:-5]
            dataset = raw(self.raw_root,
                          self.mapping[index]['Scene'],
                          seq,
                          frames=range(self.mapping[index]['Frame'] - 1,
                                       self.mapping[index]['Frame'] + 2),
                          origin=1)
            calib = {}
            calib['cam'] = {}
            calib['vel2cam'] = {}
            calib['imu2vel'] = {}
            # import pdb; pdb.set_trace()
            calib['cam']['P_rect_00'] = dataset.calib.P_rect_00
            # calib['cam']['P_rect_00'] = np.eye(4)
            # calib['cam']['P_rect_00'][0, 3] = dataset.calib.P_rect_00[0, 3] / dataset.calib.P_rect_00[0, 0]
            calib['cam']['R_rect_00'] = dataset.calib.R_rect_00
            calib['vel2cam']['RT'] = dataset.calib.T_cam0_velo_unrect
            calib['imu2vel']['RT'] = dataset.calib.T_velo_imu
            poses = [np.array([])] * 3
            poses[0] = dataset.oxts[0].T_w_imu
            poses[1] = dataset.oxts[1].T_w_imu
            poses[2] = dataset.oxts[2].T_w_imu

            # calib['cam']['baseline'] = 0.54
            calib['cam']['baseline'] = dataset.calib.b_rgb

            # calib = {}
            # calib['cam'] = loadCalib(os.path.join(path, 'calib_cam_to_cam.txt'))
            # calib['vel2cam'] = loadCalib(os.path.join(path, 'calib_velo_to_cam.txt'))
            # calib['imu2vel'] = loadCalib(os.path.join(path, 'calib_imu_to_velo.txt'))

            # # load oxts data
            # oxts = loadOxtsliteData(os.path.join(path, self.mapping[index]['Sequence']), range(self.mapping[index]['Frame'] - 1, self.mapping[index]['Frame'] + 2))

            # # get poses
            # poses = convertOxtsToPose(oxts, origin=1)

        if self.transform is not None:
            in_h, in_w, _ = tgt_img.shape
            imgs = self.transform([tgt_img] + [ref_img_past] +
                                  [ref_img_future])
            tgt_img = imgs[0]
            ref_img_past = imgs[1]
            ref_img_future = imgs[2]
            _, out_h, out_w = tgt_img.shape

            # scale projection matrix
            if len(calib) > 0 and (in_h != out_h or in_w != out_w):
                sx = float(out_h) / float(in_h)
                sy = float(out_w) / float(in_w)
                calib['cam']['P_rect_00'][0, 0] *= sx
                calib['cam']['P_rect_00'][1, 1] *= sy
                calib['cam']['P_rect_00'][0, 2] *= sx
                calib['cam']['P_rect_00'][1, 2] *= sy

        # set baseline, focal length and principal points
        if len(calib) > 0:
            calib['cam']['focal_length_x'] = calib['cam']['P_rect_00'][0, 0]
            calib['cam']['focal_length_y'] = calib['cam']['P_rect_00'][1, 1]
            calib['cam']['cx'] = calib['cam']['P_rect_00'][0, 2]
            calib['cam']['cy'] = calib['cam']['P_rect_00'][1, 2]

            # FROM IMU to IMG00
            calib['P_imu_cam'] = calib['cam']["R_rect_00"].dot(
                calib['vel2cam']["RT"].dot(calib['imu2vel']["RT"]))
            calib['P_imu_img'] = calib['cam']["P_rect_00"].dot(
                calib['P_imu_cam'])

        #if self.compression > 0 :
        #    encode_param = [int(cv2.IMWRITE_JPEG_QUALITY), 100 - self.compression]
        #    ref_img_past = cv2.imencode('.jpg', ref_img_past, encode_param)
        #    tgt_img = cv2.imencode('.jpg', tgt_img, encode_param)
        #    ref_img_future = cv2.imencode('.jpg', ref_img_future, encode_param)

        return ref_img_past, tgt_img, ref_img_future, gtFlow, gtDisp, calib, poses