#!/usr/bin/env python3 """ Reconstruct HOT3D PointMotionBench videos in one step. Runs all three stages sequentially: 1. Download train_aria TARs from bop-benchmark/hot3d (HuggingFace) 2. Extract undistorted RGB videos from each TAR 3. Trim to PointMotionBench frame windows Requirements: huggingface_hub, imageio[ffmpeg], imageio-ffmpeg, opencv-python-headless, numpy Usage: python hot3d/reconstruct_hot3d.py \ --workdir /path/to/hot3d_work \ --output-dir hot3d/rgbs # Pass a HuggingFace token if the dataset is gated: --token hf_... # Resume a partial run (skip steps already completed): --skip-download # TARs already in /train_aria/ --skip-extract # RGB videos already in /rgbs/ """ import argparse import subprocess import sys from pathlib import Path SCRIPTS_DIR = Path(__file__).resolve().parent def run_step(script_name, *args): cmd = [sys.executable, str(SCRIPTS_DIR / script_name), *args] print(f"\n{'=' * 60}") print(f"[reconstruct_hot3d] {script_name}") print(f"{'=' * 60}") result = subprocess.run(cmd) if result.returncode != 0: print(f"\nERROR: {script_name} exited with code {result.returncode}") sys.exit(result.returncode) def main(): parser = argparse.ArgumentParser( description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter ) parser.add_argument( "--workdir", required=True, type=Path, help="Working directory for intermediate files (TARs and full RGB videos)", ) parser.add_argument( "--output-dir", type=Path, default=Path(__file__).resolve().parent / "rgbs", help="Output directory for final trimmed clips (default: hot3d/rgbs/)", ) parser.add_argument( "--captions", type=Path, default=Path(__file__).resolve().parent / "hot3d_annotations.json", help="hot3d_annotations.json (default: alongside this script)", ) parser.add_argument( "--token", default=None, help="HuggingFace access token for bop-benchmark/hot3d (if gated)", ) parser.add_argument( "--skip-download", action="store_true", help="Skip step 1 — TARs already in /train_aria/", ) parser.add_argument( "--skip-extract", action="store_true", help="Skip step 2 — RGB videos already in /rgbs/", ) args = parser.parse_args() train_aria_dir = args.workdir / "train_aria" rgbs_dir = args.workdir / "rgbs" if not args.skip_download: download_args = [ "--output", str(train_aria_dir), "--captions", str(args.captions), ] if args.token: download_args += ["--token", args.token] run_step("download_train_aria.py", *download_args) if not args.skip_extract: run_step( "extract_rgbs.py", "--clips_dir", str(train_aria_dir), "--output_dir", str(rgbs_dir), ) run_step( "trim_hot3d_clips.py", "--src_dir", str(rgbs_dir), "--captions", str(args.captions), "--output_dir", str(args.output_dir), ) print(f"\n[reconstruct_hot3d] Done. Clips written to {args.output_dir}") if __name__ == "__main__": main()