ruvnet/RuView · error · ValueError
Intrinsics file {path} missing key {key!r}
Error message
Intrinsics file {path} missing key {key!r} What it means
load_intrinsics loads a precomputed camera-intrinsics JSON for the calibration flow. It accepts either a bare intrinsics dict or a full bundle containing a 'camera_intrinsics' object, then requires the keys camera_matrix, dist_coeffs, and image_size. The first missing key raises ValueError naming the file and the key.
Source
Thrown at scripts/calibration_lib.py:153
)
return {
"image_size": [int(image_size[0]), int(image_size[1])],
"camera_matrix": camera_matrix.tolist(),
"dist_coeffs": dist_coeffs.ravel().tolist(),
"reprojection_error_px": float(rms),
"source": "computed",
}
def load_intrinsics(path: Path) -> dict:
"""Load a pre-computed intrinsics JSON ({camera_matrix, dist_coeffs, image_size})."""
with open(path, "r", encoding="utf-8") as f:
data = json.load(f)
# Accept either a bare intrinsics dict or a full calibration bundle.
intr = data.get("camera_intrinsics", data)
for key in ("camera_matrix", "dist_coeffs", "image_size"):
if key not in intr:
raise ValueError(f"Intrinsics file {path} missing key {key!r}")
intr = dict(intr)
intr["source"] = "file"
return intr
# ---------------------------------------------------------------------------
# Extrinsics (camera -> room rigid transform)
# ---------------------------------------------------------------------------
def reprojection_rmse(
room_points: np.ndarray,
image_points: np.ndarray,
rvec: np.ndarray,
tvec: np.ndarray,
camera_matrix: np.ndarray,
dist_coeffs: np.ndarray,
) -> float:
proj, _ = cv2.projectPoints(room_points, rvec, tvec, camera_matrix, dist_coeffs)View on GitHub (pinned to 4685618388)
Solutions
- Regenerate the intrinsics file with the calibration flow so all three keys are written
- If importing from elsewhere, map fields explicitly: K → camera_matrix (3x3), D → dist_coeffs, [w, h] → image_size
- Pre-validate: jq 'has("camera_matrix") and has("dist_coeffs") and has("image_size")' intrinsics.json
Example fix
// before
// intrinsics.json
{"camera_matrix": [[800,0,320],[0,810,240],[0,0,1]]}
// after
// intrinsics.json
{"camera_matrix": [[800,0,320],[0,810,240],[0,0,1]],
"dist_coeffs": [0,0,0,0,0],
"image_size": [640,480]} Defensive patterns
Strategy: validation
Validate before calling
import json
REQUIRED = ("camera_matrix", "dist_coeffs", "image_size")
def intrinsics_valid(path: str) -> bool:
with open(path, encoding="utf-8") as f:
data = json.load(f)
intr = data.get("camera_intrinsics", data) if isinstance(data, dict) else {}
return isinstance(intr, dict) and all(k in intr for k in REQUIRED)
if not intrinsics_valid("intrinsics.json"):
raise SystemExit(f"intrinsics file must contain {REQUIRED}") Try / catch
try:
intr = load_intrinsics(path)
except ValueError as e:
raise SystemExit(f"regenerate the intrinsics file: {e}") from e Prevention
- Always write camera_matrix, dist_coeffs, and image_size together from the calibration flow
- Map external exports (K/D/size) explicitly instead of hand-editing
- Re-verify image_size whenever capture resolution changes
When it happens
Trigger: Passing an intrinsics file that contains only camera_matrix (no dist_coeffs/image_size), a bundle whose nested object uses different key names, or a geometry file where intrinsics were expected.
Common situations: Reusing intrinsics exported from another OpenCV pipeline that omits D or image size; hand-edited files; resolution changed after calibration so image_size is missing.
Related errors
- {path}: expected {{'nodes': [...]}} or a top-level list
- {path}: each node needs 'id' and 'position_m' [x,y,z]
- Calibration bundle {path} missing key {key!r}
- Failed to load domain configuration: {e}
- Invalid axis token {token!r}; expected one of {sorted(_AXIS_
AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16).
Data as JSON: /api/errors/9ea5a3ce03af2ddd.
Report an issue: GitHub.