(self, scene: str, frame_id: int)
| 138 | return list(range(len(self._get_frame_names(scene)))) |
| 139 | |
| 140 | def load_frame_data(self, scene: str, frame_id: int) -> Dict[str, Any]: |
| 141 | scene_dir = self.raw_data_root / scene |
| 142 | name = self._get_frame_names(scene)[frame_id] # e.g. 'DSC_0286' |
| 143 | |
| 144 | # Load per-frame calibration from NPZ |
| 145 | npz = np.load(scene_dir / 'custom_undistorted_cam' / f'{name}.npz') |
| 146 | K = npz['intrinsics'] # (3, 3) float32, for original 6048x4032 resolution |
| 147 | E = npz['extrinsics'] # (4, 4) float64, W2C matrix |
| 148 | |
| 149 | intrinsics = np.array( |
| 150 | [K[0, 0], K[1, 1], K[0, 2], K[1, 2]], dtype=np.float32 |
| 151 | ) # [fx, fy, cx, cy] |
| 152 | c2w = _w2c_to_c2w(E[:3, :3].astype(np.float32), E[:3, 3].astype(np.float32)) |
| 153 | |
| 154 | # RGB (already undistorted) |
| 155 | rgb = np.array( |
| 156 | Image.open( |
| 157 | scene_dir / 'images' / 'custom_undistorted' / f'{name}.JPG' |
| 158 | ).convert('RGB'), |
| 159 | dtype=np.uint8, |
| 160 | ) |
| 161 | |
| 162 | # Depth: same raw float32 binary format as the original eth3d dataset. |
| 163 | # File extension is .JPG but content is raw float32 (not a JPEG image). |
| 164 | depth_path = scene_dir / 'ground_truth_depth' / 'custom_undistorted' / f'{name}.JPG' |
| 165 | orig_h, orig_w = rgb.shape[:2] |
| 166 | if depth_path.exists(): |
| 167 | depth = np.fromfile(str(depth_path), dtype=np.float32).reshape(orig_h, orig_w) |
| 168 | depth = np.where(np.isfinite(depth) & (depth > 0), depth, 0.0).astype(np.float32) |
| 169 | else: |
| 170 | depth = np.zeros((orig_h, orig_w), dtype=np.float32) |
| 171 | |
| 172 | # No masks_for_images/ in eth3d_pi3; depth>0 is the sole validity criterion. |
| 173 | |
| 174 | # Resize to load_img_size width (maintaining aspect ratio) to reduce BSS storage. |
| 175 | # The original 6048x4032 DSLR resolution is impractical for BSS storage. |
| 176 | if self.load_img_size > 0 and orig_w != self.load_img_size: |
| 177 | target_width = self.load_img_size |
| 178 | h, w = rgb.shape[0], rgb.shape[1] |
| 179 | |
| 180 | aspect_ratio = float(h) / w |
| 181 | target_height = int(target_width * aspect_ratio) |
| 182 | # Round to nearest multiple of 14 for patch-based models |
| 183 | target_height = (target_height // 14) * 14 |
| 184 | |
| 185 | rgb = cv2.resize(rgb, (target_width, target_height), interpolation=cv2.INTER_LINEAR) |
| 186 | depth = cv2.resize(depth, (target_width, target_height), interpolation=cv2.INTER_NEAREST) |
| 187 | intrinsics[0] *= target_width / orig_w # fx |
| 188 | intrinsics[2] *= target_width / orig_w # cx |
| 189 | intrinsics[1] *= target_height / orig_h # fy |
| 190 | intrinsics[3] *= target_height / orig_h # cy |
| 191 | |
| 192 | return { |
| 193 | 'rgb': rgb, |
| 194 | 'depth': depth, |
| 195 | 'pose': c2w, |
| 196 | 'intrinsics': intrinsics, |
| 197 | } |
nothing calls this directly
no test coverage detected