(
self,
index: Optional[int] = None,
sequence_name: Optional[str] = None,
ids: Union[List[int], np.ndarray, None] = None,
)
| 113 | return self.get_data(index=index, ids=ids) |
| 114 | |
| 115 | def get_data( |
| 116 | self, |
| 117 | index: Optional[int] = None, |
| 118 | sequence_name: Optional[str] = None, |
| 119 | ids: Union[List[int], np.ndarray, None] = None, |
| 120 | ): |
| 121 | if sequence_name is None: |
| 122 | if index is None: |
| 123 | raise ValueError("Please specify either index or sequence_name") |
| 124 | sequence_name: str = self.sequence_list[index] |
| 125 | seq_extrinsics: np.ndarray = self.metadata[sequence_name] # (N, 3, 4) |
| 126 | seq_len: int = seq_extrinsics.shape[0] |
| 127 | |
| 128 | if ids is None: |
| 129 | ids = np.arange(seq_len).tolist() |
| 130 | elif isinstance(ids, np.ndarray): |
| 131 | assert ids.ndim == 1, f"ids should be a 1D array, but got {ids.ndim}D" |
| 132 | ids = ids.tolist() |
| 133 | |
| 134 | fx, fy, cx, cy = 554.2562584220408, 554.2562584220408, 320, 240 # hard code |
| 135 | |
| 136 | image_paths: list = [""] * len(ids) |
| 137 | images: list = [0] * len(ids) |
| 138 | depths: list = [0] * len(ids) |
| 139 | extrinsics: np.ndarray = seq_extrinsics[ids] # (N, 3, 4) -> (S, 3, 4) |
| 140 | intrinsics: np.ndarray = np.tile( |
| 141 | np.array( |
| 142 | [ |
| 143 | [fx, 0, cx], |
| 144 | [0, fy, cy], |
| 145 | [0, 0, 1 ] |
| 146 | ], |
| 147 | dtype=np.float32 |
| 148 | ), |
| 149 | reps=(len(ids), 1, 1) |
| 150 | ) # (S, 3, 3) |
| 151 | |
| 152 | for id_index, id in enumerate(ids): |
| 153 | |
| 154 | impath = osp.join(self.NRGBD_DIR, sequence_name, "images", f"img{id}.png") |
| 155 | depthpath = osp.join(self.NRGBD_DIR, sequence_name, "depth", f"depth{id}.png") |
| 156 | |
| 157 | rgb_image: Image.Image = Image.open(impath) |
| 158 | depthmap: np.ndarray = imageio.v2.imread(depthpath) |
| 159 | assert depthmap.shape == (480, 640), f"Depth map shape {depthmap.shape} does not match expected (480, 640)" |
| 160 | rgb_image: Image.Image = resize_image(rgb_image, (depthmap.shape[1], depthmap.shape[0])) |
| 161 | |
| 162 | depthmap = np.nan_to_num(depthmap.astype(np.float32), 0.0) / 1000.0 |
| 163 | depthmap[depthmap > 10] = 0 # to far, invalid |
| 164 | depthmap[depthmap < 1e-3] = 0 # to near, invalid |
| 165 | |
| 166 | rgb_image, depthmap, intrinsics[id_index] = resize_image_depth_and_intrinsic( |
| 167 | image=rgb_image, |
| 168 | depth_map=depthmap, |
| 169 | intrinsic=intrinsics[id_index], |
| 170 | output_width=self.load_img_size, # finally width = 518, height = 388 |
| 171 | ) |
| 172 |
no test coverage detected