Update single_image (102 files)
Browse files- lift_3d_pcd.py +71 -32
lift_3d_pcd.py
CHANGED
|
@@ -32,6 +32,7 @@ Examples:
|
|
| 32 |
python lift_3d_pcd.py --scene 3084 --frame camera # frame of sceneobjgt / Gen3DSR
|
| 33 |
python lift_3d_pcd.py --mask fg --gt-style mesh # only foreground (object) pixels
|
| 34 |
python lift_3d_pcd.py --stride 2 --save --no-viz # -> out/lift_3d_pcd/003025/
|
|
|
|
| 35 |
"""
|
| 36 |
|
| 37 |
from __future__ import annotations
|
|
@@ -71,6 +72,17 @@ def resolve_scene_dir(scene: str, data_root: Path) -> Path:
|
|
| 71 |
raise FileNotFoundError(f"scene folder not found: {scene} (also tried {data_root / scene})")
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def find_one(scene_dir: Path, pattern: str) -> Path | None:
|
| 75 |
hits = sorted(scene_dir.glob(pattern))
|
| 76 |
return hits[0] if hits else None
|
|
@@ -379,38 +391,9 @@ def run_checks(sample: Sample, pts_cv: np.ndarray) -> None:
|
|
| 379 |
|
| 380 |
|
| 381 |
# --------------------------------------------------------------------------------------
|
| 382 |
-
def
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
ap.add_argument("--scene", default="3025", help="scene id (e.g. 3025) or path to scene folder")
|
| 386 |
-
ap.add_argument("--data-root", type=Path, default=DEFAULT_DATA_ROOT)
|
| 387 |
-
ap.add_argument("--frame", choices=["world", "camera"], default="world",
|
| 388 |
-
help="output frame: 3D-FRONT world (z up) or OpenCV camera (= sceneobjgt)")
|
| 389 |
-
ap.add_argument("--stride", type=int, default=1, help="pixel stride when unprojecting")
|
| 390 |
-
ap.add_argument("--voxel", type=float, default=0.0, help="voxel size for downsampling (m)")
|
| 391 |
-
ap.add_argument("--mask", choices=["all", "fg", "bg"], default="all",
|
| 392 |
-
help="keep all pixels, or only foreground/background (needs bgdepth)")
|
| 393 |
-
ap.add_argument("--fg-thresh", type=float, default=0.02,
|
| 394 |
-
help="bgdepth - depth threshold (m) for a foreground pixel")
|
| 395 |
-
ap.add_argument("--color-by", choices=["rgb", "object", "height", "depth"], default="rgb")
|
| 396 |
-
ap.add_argument("--gt", dest="gt", action="store_true", default=True,
|
| 397 |
-
help="overlay sceneobjgt_*.ply in orange (default on)")
|
| 398 |
-
ap.add_argument("--no-gt", dest="gt", action="store_false")
|
| 399 |
-
ap.add_argument("--gt-style", choices=["points", "mesh", "wire"], default="points")
|
| 400 |
-
ap.add_argument("--gt-points", type=int, default=200_000)
|
| 401 |
-
ap.add_argument("--boxes", dest="boxes", action="store_true", default=True,
|
| 402 |
-
help="draw the annotated 3D boxes (default on)")
|
| 403 |
-
ap.add_argument("--no-boxes", dest="boxes", action="store_false")
|
| 404 |
-
ap.add_argument("--no-checks", dest="checks", action="store_false", default=True)
|
| 405 |
-
ap.add_argument("--save", action="store_true",
|
| 406 |
-
help="write the lifted cloud into <out-dir>/<scene_id>/")
|
| 407 |
-
ap.add_argument("--out-dir", type=Path, default=Path("out") / "lift_3d_pcd",
|
| 408 |
-
help="parent folder for saved clouds, relative to the current directory "
|
| 409 |
-
"(default: out/lift_3d_pcd)")
|
| 410 |
-
ap.add_argument("--no-viz", dest="viz", action="store_false", default=True)
|
| 411 |
-
args = ap.parse_args()
|
| 412 |
-
|
| 413 |
-
sample = Sample(resolve_scene_dir(args.scene, args.data_root))
|
| 414 |
print(sample)
|
| 415 |
print(f"K =\n{np.array2string(sample.K, precision=2, suppress_small=True)}")
|
| 416 |
print(f"frame = {args.frame} | mask = {args.mask} | stride = {args.stride} | "
|
|
@@ -455,5 +438,61 @@ def main() -> None:
|
|
| 455 |
width=1400, height=900)
|
| 456 |
|
| 457 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
if __name__ == "__main__":
|
| 459 |
main()
|
|
|
|
| 32 |
python lift_3d_pcd.py --scene 3084 --frame camera # frame of sceneobjgt / Gen3DSR
|
| 33 |
python lift_3d_pcd.py --mask fg --gt-style mesh # only foreground (object) pixels
|
| 34 |
python lift_3d_pcd.py --stride 2 --save --no-viz # -> out/lift_3d_pcd/003025/
|
| 35 |
+
python lift_3d_pcd.py --scene all --save --no-viz # every scene, headless export
|
| 36 |
"""
|
| 37 |
|
| 38 |
from __future__ import annotations
|
|
|
|
| 72 |
raise FileNotFoundError(f"scene folder not found: {scene} (also tried {data_root / scene})")
|
| 73 |
|
| 74 |
|
| 75 |
+
def resolve_scene_dirs(scene: str, data_root: Path) -> list[Path]:
|
| 76 |
+
"""Same as resolve_scene_dir, plus 'all' = every scene folder under the data root."""
|
| 77 |
+
if scene == "all":
|
| 78 |
+
dirs = sorted(p for p in data_root.iterdir()
|
| 79 |
+
if p.is_dir() and any(p.glob("annotation_*.json")))
|
| 80 |
+
if not dirs:
|
| 81 |
+
raise FileNotFoundError(f"no scene folders found under {data_root}")
|
| 82 |
+
return dirs
|
| 83 |
+
return [resolve_scene_dir(scene, data_root)]
|
| 84 |
+
|
| 85 |
+
|
| 86 |
def find_one(scene_dir: Path, pattern: str) -> Path | None:
|
| 87 |
hits = sorted(scene_dir.glob(pattern))
|
| 88 |
return hits[0] if hits else None
|
|
|
|
| 391 |
|
| 392 |
|
| 393 |
# --------------------------------------------------------------------------------------
|
| 394 |
+
def process_scene(scene_dir: Path, args) -> None:
|
| 395 |
+
"""Lift one scene: build the cloud, run the checks, save and/or visualize."""
|
| 396 |
+
sample = Sample(scene_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
print(sample)
|
| 398 |
print(f"K =\n{np.array2string(sample.K, precision=2, suppress_small=True)}")
|
| 399 |
print(f"frame = {args.frame} | mask = {args.mask} | stride = {args.stride} | "
|
|
|
|
| 438 |
width=1400, height=900)
|
| 439 |
|
| 440 |
|
| 441 |
+
def main() -> None:
|
| 442 |
+
ap = argparse.ArgumentParser(description=__doc__,
|
| 443 |
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
| 444 |
+
ap.add_argument("--scene", default="3025",
|
| 445 |
+
help="scene id (e.g. 3025), path to a scene folder, or 'all' for every "
|
| 446 |
+
"scene under --data-root (with the viewer on, one window per scene, "
|
| 447 |
+
"q closes it and opens the next)")
|
| 448 |
+
ap.add_argument("--data-root", type=Path, default=DEFAULT_DATA_ROOT)
|
| 449 |
+
ap.add_argument("--frame", choices=["world", "camera"], default="world",
|
| 450 |
+
help="output frame: 3D-FRONT world (z up) or OpenCV camera (= sceneobjgt)")
|
| 451 |
+
ap.add_argument("--stride", type=int, default=1, help="pixel stride when unprojecting")
|
| 452 |
+
ap.add_argument("--voxel", type=float, default=0.0, help="voxel size for downsampling (m)")
|
| 453 |
+
ap.add_argument("--mask", choices=["all", "fg", "bg"], default="all",
|
| 454 |
+
help="keep all pixels, or only foreground/background (needs bgdepth)")
|
| 455 |
+
ap.add_argument("--fg-thresh", type=float, default=0.02,
|
| 456 |
+
help="bgdepth - depth threshold (m) for a foreground pixel")
|
| 457 |
+
ap.add_argument("--color-by", choices=["rgb", "object", "height", "depth"], default="rgb")
|
| 458 |
+
ap.add_argument("--gt", dest="gt", action="store_true", default=True,
|
| 459 |
+
help="overlay sceneobjgt_*.ply in orange (default on)")
|
| 460 |
+
ap.add_argument("--no-gt", dest="gt", action="store_false")
|
| 461 |
+
ap.add_argument("--gt-style", choices=["points", "mesh", "wire"], default="points")
|
| 462 |
+
ap.add_argument("--gt-points", type=int, default=200_000)
|
| 463 |
+
ap.add_argument("--boxes", dest="boxes", action="store_true", default=True,
|
| 464 |
+
help="draw the annotated 3D boxes (default on)")
|
| 465 |
+
ap.add_argument("--no-boxes", dest="boxes", action="store_false")
|
| 466 |
+
ap.add_argument("--no-checks", dest="checks", action="store_false", default=True)
|
| 467 |
+
ap.add_argument("--save", action="store_true",
|
| 468 |
+
help="write the lifted cloud into <out-dir>/<scene_id>/")
|
| 469 |
+
ap.add_argument("--out-dir", type=Path, default=Path("out") / "lift_3d_pcd",
|
| 470 |
+
help="parent folder for saved clouds, relative to the current directory "
|
| 471 |
+
"(default: out/lift_3d_pcd)")
|
| 472 |
+
ap.add_argument("--no-viz", dest="viz", action="store_false", default=True)
|
| 473 |
+
args = ap.parse_args()
|
| 474 |
+
|
| 475 |
+
scene_dirs = resolve_scene_dirs(args.scene, args.data_root)
|
| 476 |
+
if len(scene_dirs) == 1:
|
| 477 |
+
process_scene(scene_dirs[0], args)
|
| 478 |
+
return
|
| 479 |
+
|
| 480 |
+
# batch mode: keep going if a single scene is broken, then report what failed
|
| 481 |
+
failed = []
|
| 482 |
+
for i, scene_dir in enumerate(scene_dirs, 1):
|
| 483 |
+
print(f"\n{'=' * 70}\n[{i}/{len(scene_dirs)}] {scene_dir.name}\n{'=' * 70}")
|
| 484 |
+
try:
|
| 485 |
+
process_scene(scene_dir, args)
|
| 486 |
+
except Exception as exc: # noqa: BLE001 - one bad scene should not stop the batch
|
| 487 |
+
print(f"!! {scene_dir.name} failed: {type(exc).__name__}: {exc}")
|
| 488 |
+
failed.append(scene_dir.name)
|
| 489 |
+
|
| 490 |
+
done = len(scene_dirs) - len(failed)
|
| 491 |
+
print(f"\ndone: {done}/{len(scene_dirs)} scenes"
|
| 492 |
+
+ (f" | failed: {', '.join(failed)}" if failed else ""))
|
| 493 |
+
if args.save:
|
| 494 |
+
print(f"output root: {args.out_dir}/")
|
| 495 |
+
|
| 496 |
+
|
| 497 |
if __name__ == "__main__":
|
| 498 |
main()
|