checkerboard_calibrate/chessboard/mod.rs
1// Copyright (C) The Strand-Braid Authors
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Pure-Rust port of OpenCV's `cv::findChessboardCorners` (the classic
5//! contour-based detector, not `findChessboardCornersSB`).
6//!
7//! This is the largest of the OpenCV routines being replaced. It is built
8//! bottom-up:
9//! 1. binarization primitives ([`binarize`]) — histogram equalization
10//! (`CALIB_CB_NORMALIZE_IMAGE`) and adaptive-mean thresholding
11//! (`CALIB_CB_ADAPTIVE_THRESH`) — **done**, bit-exact vs OpenCV,
12//! 2. quad generation from contours — **done**, all cross-checked vs OpenCV:
13//! contour finding ([`find_contours`], Suzuki-Abe), polygon approximation
14//! ([`approx_poly_dp`], Douglas-Peucker), and the convex-4-gon area filter
15//! ([`find_quads`], with [`contour_area`] / [`is_contour_convex`]),
16//! 3. linking quads into a board graph and ordering corners — **done**
17//! (synthetic tests): neighbor linking ([`link_quads`]), connected
18//! components ([`connected_components`]), consistent corner ordering
19//! ([`order_all_corners`]), board-lattice propagation ([`assign_grid`]),
20//! and row-major inner-corner readout ([`ordered_inner_corners`]),
21//! 4. board validation (size, monotonicity) and corner extraction — **done**
22//! (synthetic tests): [`check_board_monotony`] and [`extract_board`].
23//!
24//! The stages are wired together in [`find_chessboard_corners`], which on the
25//! OpenCV `left*.jpg` samples recovers OpenCV's corner positions to <=0.17px on
26//! all 13 frames. Incomplete boards
27//! are filled at the lattice level (see [`extract_board`]). The only behavior
28//! not replicated is OpenCV's exact output corner order, which is pose-dependent
29//! and not required for the pure-Rust calibrator.
30//!
31//! The detector flags requested by the strand-braid C++ wrapper are
32//! `CALIB_CB_ADAPTIVE_THRESH | CALIB_CB_NORMALIZE_IMAGE | CALIB_CB_FAST_CHECK`.
33
34mod approx;
35mod binarize;
36mod board;
37mod contour;
38mod detect;
39mod link;
40mod order;
41mod quad;
42
43pub use approx::approx_poly_dp;
44pub use binarize::{adaptive_threshold_mean, equalize_hist};
45pub use board::{check_board_monotony, extract_board};
46pub use contour::{Contour, find_contours};
47pub use detect::find_chessboard_corners;
48pub use link::{LinkedQuad, connected_components, link_quads};
49pub use order::{
50 QuadGrid, assign_grid, corner_lattice, inner_corner_lattice, order_all_corners,
51 order_quad_corners, ordered_inner_corners,
52};
53pub use quad::{Quad, contour_area, find_quads, is_contour_convex};