calib_targets_charuco/detector/
params.rs

1use crate::board::CharucoBoardSpec;
2use calib_targets_aruco::ScanDecodeConfig;
3use calib_targets_chessboard::{ChessboardParams, GridGraphParams};
4use serde::{Deserialize, Serialize};
5
6/// Configuration for the ChArUco detector.
7#[derive(Clone, Debug, Serialize, Deserialize)]
8pub struct CharucoDetectorParams {
9    /// Pixels per board square in the canonical sampling space.
10    pub px_per_square: f32,
11    /// Chessboard detection parameters.
12    pub chessboard: ChessboardParams,
13    /// ChArUco board parameters
14    pub charuco: CharucoBoardSpec,
15    /// Grid graph parameters.
16    pub graph: GridGraphParams,
17    /// Marker scan parameters.
18    ///
19    /// `CharucoDetectorParams::for_board` uses a slightly smaller inset
20    /// (`inset_frac = 0.06`) to improve real-image robustness. If
21    /// `scan.marker_size_rel <= 0.0`, it is filled from the board spec.
22    pub scan: ScanDecodeConfig,
23    /// Maximum Hamming distance for marker matching.
24    pub max_hamming: u8,
25    /// Minimal number of marker inliers needed to accept the alignment.
26    pub min_marker_inliers: usize,
27}
28
29impl CharucoDetectorParams {
30    /// Build a reasonable default configuration for the given board.
31    pub fn for_board(charuco: &CharucoBoardSpec) -> Self {
32        let chessboard = ChessboardParams {
33            min_corner_strength: 0.5,
34            min_corners: 32,
35            expected_rows: Some(charuco.rows - 1),
36            expected_cols: Some(charuco.cols - 1),
37            completeness_threshold: 0.05,
38            ..ChessboardParams::default()
39        };
40
41        let graph = GridGraphParams::default();
42
43        let scan = ScanDecodeConfig {
44            marker_size_rel: charuco.marker_size_rel,
45            inset_frac: 0.06,
46            ..ScanDecodeConfig::default()
47        };
48
49        let max_hamming = charuco.dictionary.max_correction_bits.min(2);
50
51        Self {
52            px_per_square: 60.0,
53            chessboard,
54            charuco: *charuco,
55            graph,
56            scan,
57            max_hamming,
58            min_marker_inliers: 8,
59        }
60    }
61}