Пример #1
0
    def __getitem__(self, index):
        i = index + 15
        feature, coord, out_sh, bounds = self.prepare_input(i)

        # reduce the image resolution by ratio
        H, W = int(cfg.H * cfg.ratio), int(cfg.W * cfg.ratio)
        K = self.K

        index = 0
        ray_o, ray_d, near, far, center, scale, mask_at_box = render_utils.image_rays(
            self.RT, K, bounds)

        ret = {
            'feature': feature,
            'coord': coord,
            'out_sh': out_sh,
            'ray_o': ray_o,
            'ray_d': ray_d,
            'near': near,
            'far': far,
            'mask_at_box': mask_at_box
        }

        meta = {'bounds': bounds, 'i': i, 'index': index}
        ret.update(meta)

        return ret
Пример #2
0
    def __getitem__(self, index):
        img_path = os.path.join(self.data_root, self.ims.ravel()[index])
        if self.human in ['CoreView_313', 'CoreView_315']:
            i = int(os.path.basename(img_path).split('_')[4])
        else:
            i = int(os.path.basename(img_path)[:-4])
        feature, coord, out_sh, can_bounds, bounds, Rh, Th = self.prepare_input(
            i)

        i = index // self.num_cams
        msks = self.get_mask(i)

        # reduce the image resolution by ratio
        H, W = int(cfg.H * cfg.ratio), int(cfg.W * cfg.ratio)
        msks = [
            cv2.resize(msk, (W, H), interpolation=cv2.INTER_NEAREST)
            for msk in msks
        ]
        msks = np.array(msks)

        cam_ind = self.cam_inds[index]
        K = np.array(self.cams['K'][cam_ind])
        K[:2] = K[:2] * cfg.ratio
        R = np.array(self.cams['R'][cam_ind])
        T = np.array(self.cams['T'][cam_ind]) / 1000.
        RT = np.concatenate([R, T], axis=1)

        ray_o, ray_d, near, far, center, scale, mask_at_box = render_utils.image_rays(
            RT, K, can_bounds)

        ret = {
            'feature': feature,
            'coord': coord,
            'out_sh': out_sh,
            'ray_o': ray_o,
            'ray_d': ray_d,
            'near': near,
            'far': far,
            'mask_at_box': mask_at_box
        }

        R = cv2.Rodrigues(Rh)[0].astype(np.float32)
        i = index // self.num_cams
        meta = {
            'bounds': bounds,
            'R': R,
            'Th': Th,
            'i': i,
            'index': index,
            'cam_ind': cam_ind
        }
        ret.update(meta)

        meta = {'msks': msks, 'Ks': self.Ks, 'RT': self.RT}
        ret.update(meta)

        return ret
Пример #3
0
    def __getitem__(self, index):
        i = cfg.i
        feature, coord, out_sh, can_bounds, bounds, Rh, Th = self.prepare_input(
            i, index)

        if self.human in ['CoreView_313', 'CoreView_315']:
            i = cfg.i - 1
        msks = self.get_mask(i)

        # reduce the image resolution by ratio
        H, W = int(cfg.H * cfg.ratio), int(cfg.W * cfg.ratio)
        msks = [
            cv2.resize(msk, (W, H), interpolation=cv2.INTER_NEAREST)
            for msk in msks
        ]
        msks = np.array(msks)
        K = self.K

        ray_o, ray_d, near, far, center, scale, mask_at_box = render_utils.image_rays(
            self.render_w2c[0], K, can_bounds)
        # view_RT = self.get_nearest_cam(K, self.render_w2c[index])
        # ray_d0 = render_utils.get_image_rays0(view_RT,
        #                                       self.render_w2c[index], K,
        #                                       can_bounds)

        ret = {
            'feature': feature,
            'coord': coord,
            'out_sh': out_sh,
            'ray_o': ray_o,
            'ray_d': ray_d,
            # 'ray_d0': ray_d0,
            'near': near,
            'far': far,
            'mask_at_box': mask_at_box
        }

        R = cv2.Rodrigues(Rh)[0].astype(np.float32)
        ind = i
        i = int(np.round(i / cfg.i_intv))
        i = min(i, cfg.ni - 1)
        meta = {
            'bounds': bounds,
            'R': R,
            'Th': Th,
            'i': i,
            'index': index,
            'ind': ind
        }
        ret.update(meta)

        meta = {'msks': msks, 'Ks': self.Ks, 'RT': self.RT}
        ret.update(meta)

        return ret
Пример #4
0
    def __getitem__(self, index):
        K = self.cam['K']
        D = self.cam['D']

        R = self.cam['R']
        T = self.cam['T'][:, None]

        i = 0
        feature, coord, out_sh, can_bounds, bounds, Rh, Th = self.prepare_input(
            i, index)

        msk_path = os.path.join(self.data_root, 'mask', '{}.png'.format(i))
        msk = imageio.imread(msk_path)
        msk = cv2.undistort(msk, K, D)

        # reduce the image resolution by ratio
        H, W = int(msk.shape[0] * cfg.ratio), int(msk.shape[1] * cfg.ratio)
        msk = cv2.resize(msk, (W, H), interpolation=cv2.INTER_NEAREST)
        K = K.copy().astype(np.float32)
        K[:2] = K[:2] * cfg.ratio

        RT = np.concatenate([R, T], axis=1).astype(np.float32)
        ray_o, ray_d, near, far, _, _, mask_at_box = render_utils.image_rays(
            RT, K, can_bounds)

        ret = {
            'feature': feature,
            'coord': coord,
            'out_sh': out_sh,
            'ray_o': ray_o,
            'ray_d': ray_d,
            'near': near,
            'far': far,
            'mask_at_box': mask_at_box,
            'msk': msk
        }

        R = cv2.Rodrigues(Rh)[0].astype(np.float32)
        meta = {
            'bounds': bounds,
            'R': R,
            'Th': Th,
            'i': i + 1,
            'index': index,
            'ind': i
        }
        ret.update(meta)

        Rh0 = self.params['pose'][i][:3]
        R0 = cv2.Rodrigues(Rh0)[0].astype(np.float32)
        Th0 = self.params['trans'][i].astype(np.float32)
        meta = {'R0_snap': R0, 'Th0_snap': Th0, 'K': K, 'RT': RT}
        ret.update(meta)

        return ret
Пример #5
0
    def __getitem__(self, index):
        frame_index = index
        feature, coord, out_sh, can_bounds, bounds, Rh, Th = self.prepare_input(
            frame_index)

        msks = self.get_mask(frame_index)

        # reduce the image resolution by ratio
        H, W = int(cfg.H * cfg.ratio), int(cfg.W * cfg.ratio)
        msks = [
            cv2.resize(msk, (W, H), interpolation=cv2.INTER_NEAREST)
            for msk in msks
        ]
        msks = np.array(msks)
        K = self.K

        cam_ind = index % len(self.render_w2c)
        # cam_ind = 50
        ray_o, ray_d, near, far, center, scale, mask_at_box = render_utils.image_rays(
            self.render_w2c[cam_ind], K, can_bounds)

        ret = {
            'feature': feature,
            'coord': coord,
            'out_sh': out_sh,
            'ray_o': ray_o,
            'ray_d': ray_d,
            'near': near,
            'far': far,
            'mask_at_box': mask_at_box
        }

        R = cv2.Rodrigues(Rh)[0].astype(np.float32)
        i = int(np.round(frame_index / cfg.i_intv))
        i = min(i, cfg.ni - 1)
        meta = {
            'bounds': bounds,
            'R': R,
            'Th': Th,
            'i': i,
            'index': frame_index
        }
        ret.update(meta)

        meta = {'msks': msks, 'Ks': self.Ks, 'RT': self.RT}
        ret.update(meta)

        return ret