junaid-simamdigital commited on
Commit
4c8e869
·
verified ·
1 Parent(s): c64cbe0

Add independent reprojection evaluator

Browse files
Files changed (1) hide show
  1. evaluate_reprojection.py +65 -0
evaluate_reprojection.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Evaluate point-cloud reprojection consistency against exported depth maps."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import json
7
+ from pathlib import Path
8
+
9
+ import numpy as np
10
+
11
+ from evaluate_pointcloud import load_points
12
+ from simam3d_core import reprojection_consistency
13
+
14
+
15
+ def evaluate_reprojection(points_path: str | Path, metadata_path: str | Path) -> dict:
16
+ points = load_points(points_path)
17
+ with np.load(metadata_path) as metadata:
18
+ required = {"depth", "intrinsics", "extrinsics"}
19
+ missing = sorted(required.difference(metadata.files))
20
+ if missing:
21
+ raise ValueError(f"metadata is missing required arrays: {', '.join(missing)}")
22
+ depth = np.asarray(metadata["depth"])
23
+ intrinsics = np.asarray(metadata["intrinsics"])
24
+ extrinsics = np.asarray(metadata["extrinsics"])
25
+ if depth.ndim != 3:
26
+ raise ValueError("depth metadata must have shape VxHxW")
27
+ view_count = depth.shape[0]
28
+ if intrinsics.shape != (view_count, 3, 3) or extrinsics.shape != (view_count, 4, 4):
29
+ raise ValueError("camera metadata must match depth view count")
30
+ views = []
31
+ for index in range(view_count):
32
+ metrics = reprojection_consistency(points, depth[index], intrinsics[index], extrinsics[index])
33
+ views.append({"index": index, **metrics})
34
+ return {
35
+ "mode": "reprojection_consistency_evaluation",
36
+ "points": str(Path(points_path)),
37
+ "metadata": str(Path(metadata_path)),
38
+ "point_count": int(len(points)),
39
+ "view_count": view_count,
40
+ "mean_coverage": float(np.mean([view["coverage"] for view in views])),
41
+ "mean_absolute_error": float(np.mean([view["mean_absolute_error"] for view in views])),
42
+ "median_absolute_error": float(np.median([view["median_absolute_error"] for view in views])),
43
+ "interpretation": "cross-view consistency diagnostic; not a geometric accuracy or hidden-surface claim",
44
+ "views": views,
45
+ }
46
+
47
+
48
+ def main(argv: list[str] | None = None) -> int:
49
+ parser = argparse.ArgumentParser(description=__doc__)
50
+ parser.add_argument("points", type=Path)
51
+ parser.add_argument("metadata", type=Path, help="run NPZ containing depth, intrinsics, and extrinsics")
52
+ parser.add_argument("--output", type=Path)
53
+ args = parser.parse_args(argv)
54
+ report = evaluate_reprojection(args.points, args.metadata)
55
+ destination = args.output
56
+ if destination:
57
+ destination.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
58
+ print(json.dumps(report, indent=2))
59
+ if destination:
60
+ print(f"reprojection report: {destination}")
61
+ return 0
62
+
63
+
64
+ if __name__ == "__main__":
65
+ raise SystemExit(main())