Publish sanitized stereo calibration validation dataset
Browse files- README.md +130 -0
- data/evaluation_summary.csv +14 -0
- figures/epipolar-error-map.webp +3 -0
- figures/fisheye-undistort-roundtrip.webp +3 -0
- figures/metric-vs-field-angle.webp +3 -0
- figures/mode-matched-vs-mismatched.webp +3 -0
- figures/rotation-sensitivity.webp +3 -0
- results/field_angle_and_fisheye_checks.json +55 -0
- results/stereo_epipolar_validation.json +57 -0
- results/stereo_rotation_sensitivity.json +20 -0
- tools/fisheye_roundtrip_check.py +41 -0
- tools/validate_stereo_calib.py +67 -0
README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: cc-by-nc-4.0
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
pretty_name: "Checking a Stereo Calibration on Ordinary Footage (Field Note #04)"
|
| 6 |
+
tags:
|
| 7 |
+
- robotics
|
| 8 |
+
- physical-ai
|
| 9 |
+
- egocentric
|
| 10 |
+
- stereo-vision
|
| 11 |
+
- camera-calibration
|
| 12 |
+
- fisheye
|
| 13 |
+
- epipolar-geometry
|
| 14 |
+
- kalibr
|
| 15 |
+
- opencv
|
| 16 |
+
- evaluation
|
| 17 |
+
task_categories:
|
| 18 |
+
- other
|
| 19 |
+
size_categories:
|
| 20 |
+
- n<1K
|
| 21 |
+
configs:
|
| 22 |
+
- config_name: default
|
| 23 |
+
data_files:
|
| 24 |
+
- split: train
|
| 25 |
+
path: data/evaluation_summary.csv
|
| 26 |
+
---
|
| 27 |
+
|
| 28 |
+
# Checking a Stereo Calibration on Ordinary Footage
|
| 29 |
+
|
| 30 |
+
**Origin Data Lab · Technical Field Note #04 · 23 October 2026**
|
| 31 |
+
|
| 32 |
+
[](https://origindatalab.io/technical-field-notes/stereo-calibration-check.html)
|
| 33 |
+

|
| 34 |
+

|
| 35 |
+
|
| 36 |
+
> **Short answer.** You can check whether a stereo calibration fits a device and capture mode using ordinary footage, without a target. On a 120 s, 1600×1200 head-mounted stereo recording, a Kalibr calibration from the same capture mode gave a **median angular epipolar error of 0.41 px** on 19,386 unfiltered matches; a calibration of the same camera family from a different (16:9) mode gave **1.83 px**. Two common checks can mislead on wide-angle lenses (see below).
|
| 37 |
+
|
| 38 |
+
**Code and issues:** [GitHub — origin-data-lab/stereo-calibration-validation](https://github.com/origin-data-lab/stereo-calibration-validation)
|
| 39 |
+
|
| 40 |
+
**Full article:** [Technical Field Note #04 — Checking a Stereo Calibration on Ordinary Footage](https://origindatalab.io/technical-field-notes/stereo-calibration-check.html)
|
| 41 |
+
|
| 42 |
+
---
|
| 43 |
+
|
| 44 |
+
## Key results
|
| 45 |
+
|
| 46 |
+
| Result | Value |
|
| 47 |
+
|---|---:|
|
| 48 |
+
| Median angular epipolar error, mode-matched calibration, no adjustment | **0.41 px** (19,386 matches, 29 frame pairs) |
|
| 49 |
+
| Same matches, calibration from a different capture mode | **1.83 px** |
|
| 50 |
+
| Stereo-rotation correction requested by the data | **< 0.02°** per axis |
|
| 51 |
+
| Deliberate 0.1° pitch error | median rises to **0.76 px** |
|
| 52 |
+
| Rectified vertical residual, 0–20° vs 75–90° field angle | **0.50 px → 4.05 px** (angular metric stays **0.46 px**) |
|
| 53 |
+
| `cv2.fisheye.undistortPoints` (OpenCV 5.0, defaults) | exact to ~**74°**; **4.5°** wrong at 80°, **8.0°** at 85° for this lens |
|
| 54 |
+
|
| 55 |
+
All values are from the evaluated recording and configuration; they are not universal guarantees.
|
| 56 |
+
|
| 57 |
+
## Two traps on wide-angle stereo
|
| 58 |
+
|
| 59 |
+
**1. Rectified vertical residuals inflate toward the image edge.** Projecting wide-angle rays onto a flat rectified image stretches the periphery (roughly 1/cos² of the angle), so a correct calibration looks wrong at the edges. Use an angular metric, or restrict rectified checks to the central field of view.
|
| 60 |
+
|
| 61 |
+
**2. OpenCV's default fisheye un-projection clamps the distorted angle at π/2.** With a positive k₁, θd reaches π/2 before the true ray angle reaches 90°, and every point beyond returns at the wrong angle. Run `tools/fisheye_roundtrip_check.py` with your own coefficients to see where this happens for your lens.
|
| 62 |
+
|
| 63 |
+
## Tools
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
pip install opencv-python numpy scipy pyyaml
|
| 67 |
+
|
| 68 |
+
# 1. Validate a Kalibr pinhole-equidistant stereo calibration on ordinary stereo footage
|
| 69 |
+
python tools/validate_stereo_calib.py --left left.mp4 --right right.mp4 \
|
| 70 |
+
--camchain camchain.yaml --scale 2 --out result.json
|
| 71 |
+
# --scale = video resolution / calibration resolution
|
| 72 |
+
|
| 73 |
+
# 2. Find where OpenCV's fisheye un-projection breaks for your coefficients
|
| 74 |
+
python tools/fisheye_roundtrip_check.py --camchain camchain.yaml --cam cam0 --scale 2
|
| 75 |
+
python tools/fisheye_roundtrip_check.py --k 0.12 0 0 0 --f 480 --cx 800 --cy 600
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## Repository contents
|
| 79 |
+
|
| 80 |
+
| Path | Contents |
|
| 81 |
+
|---|---|
|
| 82 |
+
| `tools/validate_stereo_calib.py` | Target-free stereo calibration check (angular epipolar error, field-angle breakdown, held-out rotation fit) |
|
| 83 |
+
| `tools/fisheye_roundtrip_check.py` | OpenCV fisheye round-trip test |
|
| 84 |
+
| `results/` | Measured results behind the article (JSON) |
|
| 85 |
+
| `data/evaluation_summary.csv` | Key numbers as a table (shown in the Dataset Viewer) |
|
| 86 |
+
| `figures/` | Figures used in the article |
|
| 87 |
+
|
| 88 |
+
The device calibration parameters and the source recording are not published in this repository.
|
| 89 |
+
|
| 90 |
+
## What this check does not verify
|
| 91 |
+
|
| 92 |
+
- **Baseline length / metric scale** — absent from the epipolar constraint.
|
| 93 |
+
- **Metric depth accuracy** — requires targets at measured distances.
|
| 94 |
+
- **Camera–IMU calibration** — time shift and extrinsics need a separate test.
|
| 95 |
+
|
| 96 |
+
## Cite
|
| 97 |
+
|
| 98 |
+
```bibtex
|
| 99 |
+
@misc{origindatalab2026fieldnote04,
|
| 100 |
+
author = {{Origin Data Lab}},
|
| 101 |
+
title = {Checking a Stereo Calibration on Ordinary Footage},
|
| 102 |
+
howpublished = {Technical Field Note \#04},
|
| 103 |
+
year = {2026},
|
| 104 |
+
url = {https://origindatalab.io/technical-field-notes/stereo-calibration-check.html}
|
| 105 |
+
}
|
| 106 |
+
```
|
| 107 |
+
|
| 108 |
+
Or:
|
| 109 |
+
|
| 110 |
+
```
|
| 111 |
+
Origin Data Lab (2026). Checking a Stereo Calibration on Ordinary Footage. Technical Field Note #04.
|
| 112 |
+
https://origindatalab.io/technical-field-notes/stereo-calibration-check.html
|
| 113 |
+
```
|
| 114 |
+
|
| 115 |
+
## License
|
| 116 |
+
|
| 117 |
+
- Code in `tools/`: MIT
|
| 118 |
+
- Text, results and figures: [CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/) — free to share and adapt for non-commercial use with attribution to Origin Data Lab.
|
| 119 |
+
|
| 120 |
+
## Related
|
| 121 |
+
|
| 122 |
+
- [All Technical Field Notes](https://origindatalab.io/technical-field-notes/)
|
| 123 |
+
- [한국어 — 스테레오 캘리브레이션 검증 (Field Note #04)](https://origindatalab.io/ko/technical-field-notes/stereo-calibration-check.html)
|
| 124 |
+
- [#03 Stereo + IMU Egocentric Capture](https://origindatalab.io/technical-field-notes/stereo-imu-egocentric-sample.html) · [dataset card](https://huggingface.co/datasets/origindatalab/stereo-imu-egocentric-evaluation)
|
| 125 |
+
|
| 126 |
+
---
|
| 127 |
+
|
| 128 |
+
**Origin Data Lab** — real-world data production for Physical AI and robotics · [origindatalab.io](https://origindatalab.io) · [contact@origindatalab.io](mailto:contact@origindatalab.io)
|
| 129 |
+
|
| 130 |
+
Need per-device, per-capture-mode stereo calibration validated on your own footage? [Contact us](https://origindatalab.io/contact.html).
|
data/evaluation_summary.csv
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
metric,value,note
|
| 2 |
+
angular_epipolar_median_px,0.408,"mode-matched calibration, 19,386 unfiltered matches"
|
| 3 |
+
angular_epipolar_p90_px,1.685,"mode-matched calibration"
|
| 4 |
+
mismatched_mode_calibration_median_px,1.835,"same matches, calibration from a 16:9 capture mode"
|
| 5 |
+
mismatched_mode_calibration_p90_px,4.165,"same matches, calibration from a 16:9 capture mode"
|
| 6 |
+
stereo_pairs_sampled,29,"every 4 s across 120 s"
|
| 7 |
+
heldout_median_as_supplied_px,0.399,"alternate-pair held-out evaluation"
|
| 8 |
+
heldout_median_after_3dof_fit_px,0.374,"fitted correction about -0.011/-0.008/-0.006 deg"
|
| 9 |
+
heldout_median_with_0p1deg_pitch_error_px,0.759,"deliberate perturbation"
|
| 10 |
+
rectified_vertical_median_0_20deg_px,0.503,"rectified metric, centre"
|
| 11 |
+
rectified_vertical_median_75_90deg_px,4.049,"rectified metric, periphery"
|
| 12 |
+
angular_median_75_90deg_px,0.461,"angular metric, periphery"
|
| 13 |
+
opencv_fisheye_roundtrip_error_80deg,4.45,"degrees; OpenCV 5.0 defaults"
|
| 14 |
+
opencv_fisheye_roundtrip_error_85deg,8.04,"degrees; OpenCV 5.0 defaults"
|
figures/epipolar-error-map.webp
ADDED
|
Git LFS Details
|
figures/fisheye-undistort-roundtrip.webp
ADDED
|
Git LFS Details
|
figures/metric-vs-field-angle.webp
ADDED
|
Git LFS Details
|
figures/mode-matched-vs-mismatched.webp
ADDED
|
Git LFS Details
|
figures/rotation-sensitivity.webp
ADDED
|
Git LFS Details
|
results/field_angle_and_fisheye_checks.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bins": [
|
| 3 |
+
"0\u201320\u00b0",
|
| 4 |
+
"20\u201340\u00b0",
|
| 5 |
+
"40\u201355\u00b0",
|
| 6 |
+
"55\u201365\u00b0",
|
| 7 |
+
"65\u201375\u00b0",
|
| 8 |
+
"75\u201390\u00b0"
|
| 9 |
+
],
|
| 10 |
+
"n": [
|
| 11 |
+
1373,
|
| 12 |
+
5777,
|
| 13 |
+
4330,
|
| 14 |
+
2873,
|
| 15 |
+
3784,
|
| 16 |
+
1249
|
| 17 |
+
],
|
| 18 |
+
"angular_median": [
|
| 19 |
+
0.478,
|
| 20 |
+
0.413,
|
| 21 |
+
0.311,
|
| 22 |
+
0.422,
|
| 23 |
+
0.451,
|
| 24 |
+
0.461
|
| 25 |
+
],
|
| 26 |
+
"rectified_median": [
|
| 27 |
+
0.503,
|
| 28 |
+
0.514,
|
| 29 |
+
0.504,
|
| 30 |
+
0.995,
|
| 31 |
+
1.69,
|
| 32 |
+
4.049
|
| 33 |
+
],
|
| 34 |
+
"angular_p90": [
|
| 35 |
+
1.894,
|
| 36 |
+
1.594,
|
| 37 |
+
1.559,
|
| 38 |
+
2.029,
|
| 39 |
+
1.676,
|
| 40 |
+
1.796
|
| 41 |
+
],
|
| 42 |
+
"rectified_p90": [
|
| 43 |
+
2.024,
|
| 44 |
+
2.05,
|
| 45 |
+
2.827,
|
| 46 |
+
6.008,
|
| 47 |
+
8.64,
|
| 48 |
+
23.036
|
| 49 |
+
],
|
| 50 |
+
"opencv_roundtrip_first_angle_err_gt_0p1deg": 74.0,
|
| 51 |
+
"opencv_roundtrip_err_at_80": 4.45,
|
| 52 |
+
"opencv_roundtrip_err_at_85": 8.04,
|
| 53 |
+
"own_max_err": 2.842170943040401e-14,
|
| 54 |
+
"note": "Same 19,386 matches; angular epipolar error vs rectified vertical residual by field angle of the left-image point; OpenCV fisheye round-trip test (OpenCV 5.0, default settings)."
|
| 55 |
+
}
|
results/stereo_epipolar_validation.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"calibration": "Kalibr pinhole-equidistant stereo calibration, solved at 800x600 (exact 0.5x of the 1600x1200 capture mode); parameters not published",
|
| 3 |
+
"scale": 2.0,
|
| 4 |
+
"px_per_deg_at_centre": 8.419,
|
| 5 |
+
"pairs_sampled": 29,
|
| 6 |
+
"angular_epipolar_error_all": {
|
| 7 |
+
"n": 19386,
|
| 8 |
+
"median_px": 0.408,
|
| 9 |
+
"p75_px": 0.798,
|
| 10 |
+
"p90_px": 1.685
|
| 11 |
+
},
|
| 12 |
+
"by_field_angle": {
|
| 13 |
+
"0-30deg": {
|
| 14 |
+
"n": 4026,
|
| 15 |
+
"median_px": 0.453,
|
| 16 |
+
"p75_px": 0.827,
|
| 17 |
+
"p90_px": 1.664
|
| 18 |
+
},
|
| 19 |
+
"30-50deg": {
|
| 20 |
+
"n": 6061,
|
| 21 |
+
"median_px": 0.334,
|
| 22 |
+
"p75_px": 0.676,
|
| 23 |
+
"p90_px": 1.546
|
| 24 |
+
},
|
| 25 |
+
"50-70deg": {
|
| 26 |
+
"n": 5943,
|
| 27 |
+
"median_px": 0.425,
|
| 28 |
+
"p75_px": 0.778,
|
| 29 |
+
"p90_px": 1.899
|
| 30 |
+
},
|
| 31 |
+
"70-100deg": {
|
| 32 |
+
"n": 3356,
|
| 33 |
+
"median_px": 0.435,
|
| 34 |
+
"p75_px": 1.065,
|
| 35 |
+
"p90_px": 1.699
|
| 36 |
+
}
|
| 37 |
+
},
|
| 38 |
+
"grid_3x3_median_px": {
|
| 39 |
+
"row0_col0": 0.353,
|
| 40 |
+
"row0_col1": 0.448,
|
| 41 |
+
"row0_col2": 1.163,
|
| 42 |
+
"row1_col0": 0.548,
|
| 43 |
+
"row1_col1": 0.444,
|
| 44 |
+
"row1_col2": 0.318,
|
| 45 |
+
"row2_col0": 1.17,
|
| 46 |
+
"row2_col1": 0.568,
|
| 47 |
+
"row2_col2": 0.331
|
| 48 |
+
},
|
| 49 |
+
"heldout_median_px_before": 0.399,
|
| 50 |
+
"heldout_median_px_after_3dof_fit": 0.374,
|
| 51 |
+
"fitted_stereo_rotation_correction_deg": [
|
| 52 |
+
-0.0109,
|
| 53 |
+
-0.0077,
|
| 54 |
+
-0.0062
|
| 55 |
+
],
|
| 56 |
+
"interpretation": "Unfiltered matches (no RANSAC). Median near the matching noise floor (~0.3-0.6 px) and a fitted correction of a few hundredths of a degree indicate the calibration fits this device and sensor mode. Baseline length / metric depth are NOT tested."
|
| 57 |
+
}
|
results/stereo_rotation_sensitivity.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"fitted_correction_deg": [
|
| 3 |
+
-0.011,
|
| 4 |
+
-0.008,
|
| 5 |
+
-0.006
|
| 6 |
+
],
|
| 7 |
+
"heldout_median_px_after_fit": 0.374,
|
| 8 |
+
"sensitivity_heldout_median_px": {
|
| 9 |
+
"x(pitch)_0.1deg": 0.759,
|
| 10 |
+
"x(pitch)_0.2deg": 1.346,
|
| 11 |
+
"x(pitch)_0.5deg": 3.337,
|
| 12 |
+
"y(yaw)_0.1deg": 0.547,
|
| 13 |
+
"y(yaw)_0.2deg": 0.663,
|
| 14 |
+
"y(yaw)_0.5deg": 1.176,
|
| 15 |
+
"z(roll)_0.1deg": 0.641,
|
| 16 |
+
"z(roll)_0.2deg": 0.988,
|
| 17 |
+
"z(roll)_0.5deg": 2.224
|
| 18 |
+
},
|
| 19 |
+
"heldout_median_px_as_supplied": 0.399
|
| 20 |
+
}
|
tools/fisheye_roundtrip_check.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Check where OpenCV's cv2.fisheye.undistortPoints stops being exact for YOUR equidistant (Kalibr / OpenCV fisheye) coefficients.
|
| 2 |
+
|
| 3 |
+
In the equidistant model the distorted angle is theta_d = theta * (1 + k1 theta^2 + k2 theta^4 + k3 theta^6 + k4 theta^8).
|
| 4 |
+
OpenCV clamps theta_d at pi/2 when un-projecting, so with positive k1 every point whose true ray angle maps beyond
|
| 5 |
+
theta_d = pi/2 comes back at the wrong angle. This script projects rays at known angles, un-projects them with OpenCV
|
| 6 |
+
and with a Newton inversion of theta_d(theta), and prints both errors.
|
| 7 |
+
|
| 8 |
+
Usage:
|
| 9 |
+
python fisheye_roundtrip_check.py --k 0.12 0.0 0.0 0.0 --f 480 --cx 800 --cy 600
|
| 10 |
+
python fisheye_roundtrip_check.py --camchain camchain.yaml --cam cam0 --scale 2
|
| 11 |
+
"""
|
| 12 |
+
import argparse,numpy as np,cv2
|
| 13 |
+
ap=argparse.ArgumentParser();ap.add_argument('--k',type=float,nargs=4);ap.add_argument('--f',type=float,default=500.0)
|
| 14 |
+
ap.add_argument('--cx',type=float,default=800.0);ap.add_argument('--cy',type=float,default=600.0)
|
| 15 |
+
ap.add_argument('--camchain');ap.add_argument('--cam',default='cam0');ap.add_argument('--scale',type=float,default=1.0);a=ap.parse_args()
|
| 16 |
+
if a.camchain:
|
| 17 |
+
import yaml;c=yaml.safe_load(open(a.camchain))[a.cam];fx,fy,cx,cy=c['intrinsics'];s=a.scale;off=(s-1)/2
|
| 18 |
+
k=np.array(c['distortion_coeffs'],float);K=np.array([[fx*s,0,cx*s+off],[0,fy*s,cy*s+off],[0,0,1.]])
|
| 19 |
+
else:
|
| 20 |
+
k=np.array(a.k,float);K=np.array([[a.f,0,a.cx],[0,a.f,a.cy],[0,0,1.]])
|
| 21 |
+
def theta_d(t):return t*(1+k[0]*t**2+k[1]*t**4+k[2]*t**6+k[3]*t**8)
|
| 22 |
+
def newton(td):
|
| 23 |
+
t=td.copy()
|
| 24 |
+
for _ in range(30):
|
| 25 |
+
t-= (theta_d(t)-td)/(1+3*k[0]*t**2+5*k[1]*t**4+7*k[2]*t**6+9*k[3]*t**8)
|
| 26 |
+
return t
|
| 27 |
+
deg=np.arange(30,91,1.0);th=np.radians(deg)
|
| 28 |
+
P=np.c_[np.tan(th)*np.cos(.7),np.tan(th)*np.sin(.7),np.ones(len(th))]
|
| 29 |
+
pix=cv2.fisheye.projectPoints(P.reshape(-1,1,3),np.zeros(3),np.zeros(3),K,k.reshape(4,1))[0].reshape(-1,2)
|
| 30 |
+
ocv=cv2.fisheye.undistortPoints(pix.reshape(-1,1,2),K,k.reshape(4,1)).reshape(-1,2)
|
| 31 |
+
ocv_deg=np.degrees(np.arctan(np.hypot(ocv[:,0],ocv[:,1])))
|
| 32 |
+
x=(pix[:,0]-K[0,2])/K[0,0];y=(pix[:,1]-K[1,2])/K[1,1];new_deg=np.degrees(newton(np.hypot(x,y)))
|
| 33 |
+
lim=None
|
| 34 |
+
for t in np.linspace(0,np.pi/2,20001):
|
| 35 |
+
if theta_d(t)>=np.pi/2:lim=np.degrees(t);break
|
| 36 |
+
print(f'OpenCV {cv2.__version__}; k = {k.tolist()}')
|
| 37 |
+
print('theta_d reaches pi/2 at true angle:',f'{lim:.1f} deg' if lim else 'never (within 90 deg)')
|
| 38 |
+
print(f'{"angle":>6} {"radius_px":>10} {"opencv_err_deg":>15} {"newton_err_deg":>15}')
|
| 39 |
+
for d,p,o,n in zip(deg,pix,ocv_deg,new_deg):
|
| 40 |
+
if d%5==0 or (lim and lim-3<=d<=lim+3):
|
| 41 |
+
print(f'{d:6.0f} {np.hypot(*(p-K[:2,2])):10.0f} {d-o:15.3f} {d-n:15.2e}')
|
tools/validate_stereo_calib.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Validate a Kalibr stereo calibration (pinhole-equidistant) on an ordinary stereo recording - no target needed.
|
| 2 |
+
|
| 3 |
+
Measures the angular epipolar error of SIFT matches between simultaneous left/right frames:
|
| 4 |
+
how far each right-camera ray lies from the epipolar plane predicted by the calibration.
|
| 5 |
+
Tests intrinsics + distortion + stereo rotation + baseline DIRECTION. It does NOT test baseline LENGTH (metric scale).
|
| 6 |
+
|
| 7 |
+
Usage (Windows or Linux, Python 3.9+, pip install opencv-python numpy pyyaml scipy):
|
| 8 |
+
python validate_stereo_calib.py --left left.mp4 --right right.mp4 --camchain bmi088_calibration-camchain.yaml --scale 2 --out result.json
|
| 9 |
+
--scale: video resolution / calibration resolution (e.g. 1600x1200 video, 800x600 calibration -> 2)
|
| 10 |
+
"""
|
| 11 |
+
import argparse,json,cv2,numpy as np,yaml
|
| 12 |
+
from scipy.optimize import least_squares
|
| 13 |
+
ap=argparse.ArgumentParser();ap.add_argument('--left',required=True);ap.add_argument('--right',required=True);ap.add_argument('--camchain',required=True)
|
| 14 |
+
ap.add_argument('--scale',type=float,default=1.0);ap.add_argument('--step',type=float,default=4.0,help='seconds between sampled frame pairs')
|
| 15 |
+
ap.add_argument('--out',default='stereo_calib_validation.json');a=ap.parse_args()
|
| 16 |
+
cc=yaml.safe_load(open(a.camchain))
|
| 17 |
+
for c in ('cam0','cam1'):
|
| 18 |
+
assert cc[c]['distortion_model']=='equidistant' and cc[c]['camera_model']=='pinhole','this script handles pinhole-equidistant (Kalibr) only'
|
| 19 |
+
def scaled(intr,s):
|
| 20 |
+
fx,fy,cx,cy=intr;off=(s-1)/2 # OpenCV pixel-centre convention: x_full = s*x_small + (s-1)/2
|
| 21 |
+
return fx*s,fy*s,cx*s+off,cy*s+off
|
| 22 |
+
I0=scaled(cc['cam0']['intrinsics'],a.scale);I1=scaled(cc['cam1']['intrinsics'],a.scale)
|
| 23 |
+
k0=np.array(cc['cam0']['distortion_coeffs']);k1=np.array(cc['cam1']['distortion_coeffs'])
|
| 24 |
+
Tm=np.array(cc['cam1']['T_cn_cnm1']);R=Tm[:3,:3];T=Tm[:3,3]
|
| 25 |
+
def rays(p,I,k):
|
| 26 |
+
fx,fy,cx,cy=I;x=(p[:,0]-cx)/fx;y=(p[:,1]-cy)/fy;td=np.hypot(x,y);t=td.copy()
|
| 27 |
+
for _ in range(30):
|
| 28 |
+
f=t*(1+k[0]*t**2+k[1]*t**4+k[2]*t**6+k[3]*t**8)-td;t-=f/(1+3*k[0]*t**2+5*k[1]*t**4+7*k[2]*t**6+9*k[3]*t**8)
|
| 29 |
+
s=np.where(td>1e-9,np.sin(t)/np.maximum(td,1e-12),1.0);v=np.c_[x*s,y*s,np.cos(t)];return v/np.linalg.norm(v,axis=1,keepdims=True),np.degrees(t)
|
| 30 |
+
def epi(r0,r1,Rm,Tv):
|
| 31 |
+
E=np.array([[0,-Tv[2],Tv[1]],[Tv[2],0,-Tv[0]],[-Tv[1],Tv[0],0]])@Rm;n=(E@r0.T).T;n/=np.linalg.norm(n,axis=1,keepdims=True)
|
| 32 |
+
return np.degrees(np.arcsin(np.clip((n*r1).sum(1),-1,1)))
|
| 33 |
+
px_per_deg=I0[0]*np.pi/180
|
| 34 |
+
L=cv2.VideoCapture(a.left);Q=cv2.VideoCapture(a.right);dur=L.get(cv2.CAP_PROP_FRAME_COUNT)/L.get(cv2.CAP_PROP_FPS)
|
| 35 |
+
sift=cv2.SIFT_create(nfeatures=3000);bf=cv2.BFMatcher();D=[]
|
| 36 |
+
for sec in np.arange(a.step,dur-1,a.step):
|
| 37 |
+
g=[]
|
| 38 |
+
for c in (L,Q):
|
| 39 |
+
c.set(cv2.CAP_PROP_POS_MSEC,sec*1000);ok,f=c.read()
|
| 40 |
+
if not ok:break
|
| 41 |
+
g.append(cv2.cvtColor(f,cv2.COLOR_BGR2GRAY))
|
| 42 |
+
if len(g)<2:continue
|
| 43 |
+
kp=[sift.detectAndCompute(x,None) for x in g];m=bf.knnMatch(kp[0][1],kp[1][1],k=2);good=[x for x,y in m if x.distance<.7*y.distance]
|
| 44 |
+
if len(good)<30:continue
|
| 45 |
+
p0=np.float64([kp[0][0][x.queryIdx].pt for x in good]);p1=np.float64([kp[1][0][x.trainIdx].pt for x in good])
|
| 46 |
+
r0,t0=rays(p0,I0,k0);r1,_=rays(p1,I1,k1);D.append((float(sec),p0,r0,r1,t0));print(f'{sec:6.1f}s matches {len(good)}',flush=True)
|
| 47 |
+
def stats(e):e=np.abs(e);return dict(n=int(len(e)),median_px=round(float(np.median(e)),3),p75_px=round(float(np.percentile(e,75)),3),p90_px=round(float(np.percentile(e,90)),3))
|
| 48 |
+
allerr=np.concatenate([epi(r0,r1,R,T) for _,_,r0,r1,_ in D])*px_per_deg
|
| 49 |
+
ang=np.concatenate([t for *_,t in D]);P=np.concatenate([p for _,p,*_ in D])
|
| 50 |
+
tr=D[::2];te=D[1::2]
|
| 51 |
+
def err(sub,d):Rd=cv2.Rodrigues(np.radians(d))[0];return np.concatenate([epi(r0,r1,Rd@R,T) for _,_,r0,r1,_ in sub])*px_per_deg
|
| 52 |
+
fit=least_squares(lambda d:err(tr,d),np.zeros(3),loss='soft_l1',f_scale=1.0)
|
| 53 |
+
W,H=int(L.get(cv2.CAP_PROP_FRAME_WIDTH)),int(L.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 54 |
+
grid={}
|
| 55 |
+
for j in range(3):
|
| 56 |
+
for i in range(3):
|
| 57 |
+
s=(P[:,0]>=i*W/3)&(P[:,0]<(i+1)*W/3)&(P[:,1]>=j*H/3)&(P[:,1]<(j+1)*H/3)
|
| 58 |
+
if s.sum()>20:grid[f'row{j}_col{i}']=round(float(np.median(np.abs(allerr[s]))),3)
|
| 59 |
+
res=dict(calibration=a.camchain,scale=a.scale,px_per_deg_at_centre=round(px_per_deg,3),pairs_sampled=len(D),
|
| 60 |
+
angular_epipolar_error_all=stats(allerr),
|
| 61 |
+
by_field_angle={f'{lo}-{hi}deg':stats(allerr[(ang>=lo)&(ang<hi)]) for lo,hi in [(0,30),(30,50),(50,70),(70,100)] if ((ang>=lo)&(ang<hi)).sum()>20},
|
| 62 |
+
grid_3x3_median_px=grid,
|
| 63 |
+
heldout_median_px_before=round(float(np.median(np.abs(err(te,np.zeros(3))))),3),
|
| 64 |
+
heldout_median_px_after_3dof_fit=round(float(np.median(np.abs(err(te,fit.x)))),3),
|
| 65 |
+
fitted_stereo_rotation_correction_deg=np.round(fit.x,4).tolist(),
|
| 66 |
+
interpretation='Unfiltered matches (no RANSAC). Median near the matching noise floor (~0.3-0.6 px) and a fitted correction of a few hundredths of a degree indicate the calibration fits this device and sensor mode. Baseline length / metric depth are NOT tested.')
|
| 67 |
+
print(json.dumps(res,indent=1));json.dump(res,open(a.out,'w'),indent=1)
|