Loads images (using strict original logic) and aligns optional conditions (poses, depths, intrinsics). Args: path: Path to images or video. conditions: Dict containing numpy arrays: - 'intrinsics': (N_total, 3, 3) - 'poses': (N_to
(path="data/truck", conditions=None, interval=1, PIXEL_LIMIT=255000, verbose=True, device='cpu')
| 226 | ply_data.write(path) |
| 227 | |
| 228 | def load_multimodal_data(path="data/truck", conditions=None, interval=1, PIXEL_LIMIT=255000, verbose=True, device='cpu'): |
| 229 | """ |
| 230 | Loads images (using strict original logic) and aligns optional conditions (poses, depths, intrinsics). |
| 231 | |
| 232 | Args: |
| 233 | path: Path to images or video. |
| 234 | conditions: Dict containing numpy arrays: |
| 235 | - 'intrinsics': (N_total, 3, 3) |
| 236 | - 'poses': (N_total, 4, 4) |
| 237 | - 'depths': (N_total, H, W) |
| 238 | interval: Sampling interval. |
| 239 | |
| 240 | Returns: |
| 241 | dict: { |
| 242 | 'images': (N, 3, H, W), |
| 243 | 'poses': (N, 4, 4) or None, |
| 244 | 'depths': (N, H, W) or None, |
| 245 | 'intrinsics': (N, 3, 3) or None |
| 246 | } |
| 247 | """ |
| 248 | sources = [] |
| 249 | |
| 250 | # --- 1. Load image paths or video frames --- |
| 251 | if osp.isdir(path): |
| 252 | if verbose: |
| 253 | print(f"Loading images from directory: {path}") |
| 254 | filenames = sorted([x for x in os.listdir(path) if x.lower().endswith((".png", ".jpg", ".jpeg"))]) |
| 255 | for i in range(0, len(filenames), interval): |
| 256 | img_path = osp.join(path, filenames[i]) |
| 257 | try: |
| 258 | sources.append(Image.open(img_path).convert("RGB")) |
| 259 | except Exception as e: |
| 260 | print(f"Could not load image {filenames[i]}: {e}") |
| 261 | elif path.lower().endswith(".mp4"): |
| 262 | if verbose: |
| 263 | print(f"Loading frames from video: {path}") |
| 264 | cap = cv2.VideoCapture(path) |
| 265 | if not cap.isOpened(): |
| 266 | raise OSError(f"Cannot open video file: {path}") |
| 267 | frame_idx = 0 |
| 268 | while True: |
| 269 | ret, frame = cap.read() |
| 270 | if not ret: |
| 271 | break |
| 272 | if frame_idx % interval == 0: |
| 273 | rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) |
| 274 | sources.append(Image.fromarray(rgb_frame)) |
| 275 | frame_idx += 1 |
| 276 | cap.release() |
| 277 | else: |
| 278 | raise ValueError(f"Unsupported path. Must be a directory or a .mp4 file: {path}") |
| 279 | |
| 280 | if not sources: |
| 281 | print("No images found or loaded.") |
| 282 | return {'images': torch.empty(0)} |
| 283 | |
| 284 | if verbose: |
| 285 | print(f"Found {len(sources)} images/frames. Processing...") |