How yumashino/camera-calibration-with-charuco-board works
Purpose and Entry Points
This is a local Python/OpenCV utility for calibrating a camera from a video of a ChArUco board. It computes intrinsics, lens distortion, reprojection error, field of view, image-center shifts, and board-to-camera distance statistics.
Primary calibration entry point: calibrate_camera_with_charuco.py.
Board-generation entry point: generate_charuco_board.py.
Board Definition and Physical Setup
generate_charuco_board.py creates the ChArUco target used throughout the calibration workflow. Its dictionary and board grid dimensions must align with the physical board and calibration input.
The calibration configuration supplies physical board measurements plus camera/lens assumptions through YAML, exemplified by sample_calibration_input.yaml.
Video-to-Detection Stage
calibrate_camera_with_charuco.py consumes a video path and YAML configuration. It processes video frames, detects ArUco markers, and interpolates ChArUco corners. Only frames with usable detected corners become calibration observations.
An optional image-display mode exposes the detection boundary for visual validation; the default operational boundary is video input to accumulated corner observations.
Calibration Solve
The accepted corner/ID observations and configured board geometry feed OpenCV’s ChArUco calibration routines. The solve produces the camera matrix (fx, fy, cx, cy), distortion coefficients, and RMS reprojection error.
This stage depends on the OpenCV contrib ArUco APIs, whose version is materially constrained by requirements.txt.
Derived Camera and Pose Metrics
After calibration, the program derives horizontal/vertical field of view and principal-point shifts from the solved intrinsics. Per-observation board pose/distance estimates are aggregated into mean, variance, and standard deviation distance metrics.
These results represent calibration quality and capture-coverage diagnostics, rather than a persistent runtime service.
Output Contract
Results are serialized as a timestamped YAML file associated with the input video. The expected schema is demonstrated in sample_calibration_input_results_20240210_2131.yaml, including matrix, distortion, reprojection error, detected-frame count, FOV, shifts, and distance statistics.
The repository also includes sample_calibration_video.mp4 as a local sample input artifact.
Runtime and Infrastructure
Runtime is standalone Python 3.6+ with dependencies installed from requirements.txt; no server, database, cloud infrastructure, or external API is indicated. Inputs and outputs are local filesystem artifacts: video, YAML configuration, generated board image, and calibration-results YAML.
Main entry points: calibrate_camera_with_charuco.py Intrinsic calibration solve · sample_calibration_input.yaml Calibration configuration · requirements.txt OpenCV contrib ArUco · sample_calibration_input_results_20240210_2131.yaml Timestamped results YAML
Components 13
Board setup
- Board generator · Creates the physical ChArUco target image.
generate_charuco_board.py - ChArUco board image
Calibration pipeline
- Camera calibration · Standalone video-based calibration workflow.
calibrate_camera_with_charuco.py - Frame corner detection · Detects markers and interpolates ChArUco corners per video frame.
calibrate_camera_with_charuco.py - Accepted observations · Only frames with usable ChArUco corners are retained.
- Intrinsic calibration solve · Computes camera matrix, distortion, and RMS reprojection error.
calibrate_camera_with_charuco.py - Camera and pose metrics · Derives FOV, principal-point shifts, and distance statistics.
calibrate_camera_with_charuco.py - Detection display mode
calibrate_camera_with_charuco.py
Local artifacts
- Calibration video
sample_calibration_video.mp4 - Calibration configuration · Provides board measurements and camera/lens assumptions.
sample_calibration_input.yaml - Timestamped results YAML · Contains solved parameters, quality metrics, and diagnostics.
sample_calibration_input_results_20240210_2131.yaml
Other components
- OpenCV contrib ArUco · Version-constrained ChArUco detection and calibration APIs.
requirements.txt - Python 3.6+
Connections 16
- Board generator → ChArUco board image: generates
- ChArUco board image → Calibration configuration: dimensions must align
- Python 3.6+ → Camera calibration: runs
- OpenCV contrib ArUco → Frame corner detection: detects corners
- OpenCV contrib ArUco → Intrinsic calibration solve: solves calibration
- Calibration video → Camera calibration: input
- Calibration configuration → Camera calibration: board and lens settings
- Camera calibration → Frame corner detection: processes frames
- Frame corner detection → Accepted observations: retains usable frames
- Frame corner detection → Detection display mode: optional visualization
- Accepted observations → Intrinsic calibration solve: corner observations
- Calibration configuration → Intrinsic calibration solve: board geometry
- Intrinsic calibration solve → Camera and pose metrics: intrinsics and error
- Accepted observations → Camera and pose metrics: per-frame poses
- Intrinsic calibration solve → Timestamped results YAML: calibration results
- Camera and pose metrics → Timestamped results YAML: derived diagnostics