File size: 1,989 Bytes
77731f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
from __future__ import annotations

import argparse
from pathlib import Path

from _common import read_json, write_csv


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(description="Audit generated CM-EVS render artifacts.")
    parser.add_argument("--render-dir", type=Path, required=True)
    parser.add_argument("--metadata", type=Path, required=True)
    parser.add_argument("--output", type=Path, required=True)
    parser.add_argument("--limit", type=int, default=50)
    return parser.parse_args()


def has_magic(path: Path, magic: bytes) -> bool:
    if not path.exists():
        return False
    with path.open("rb") as f:
        return f.read(len(magic)) == magic


def main() -> None:
    args = parse_args()
    selected_doc = read_json(args.metadata)
    rows = []
    for item in selected_doc.get("selected_viewpoints", [])[: args.limit]:
        cid = str(item["candidate_id"])
        rank = int(item["rank"])
        stem = f"{rank:03d}_{cid}"
        rgb = args.render_dir / f"{stem}_rgb.png"
        depth = args.render_dir / f"{stem}_depth.npy"
        pose = args.render_dir / f"{stem}_pose.json"
        pose_ok = False
        if pose.exists():
            try:
                read_json(pose)
                pose_ok = True
            except Exception:
                pose_ok = False
        rows.append(
            {
                "candidate_id": cid,
                "rank": rank,
                "rgb_exists": rgb.exists(),
                "rgb_png_magic": has_magic(rgb, b"\x89PNG\r\n\x1a\n"),
                "depth_exists": depth.exists(),
                "depth_npy_magic": has_magic(depth, b"\x93NUMPY"),
                "pose_exists": pose.exists(),
                "pose_json_valid": pose_ok,
                "passed": rgb.exists() and depth.exists() and pose_ok,
            }
        )
    write_csv(args.output, rows)
    print(f"Wrote {args.output}")


if __name__ == "__main__":
    main()