Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

DetectConfig

DetectConfig is the top-level configuration struct for the ringgrid detection pipeline. It aggregates all sub-configurations – from proposal generation and edge sampling through homography RANSAC and self-undistort – into a single value that drives every stage of detection.

Construction

DetectConfig is designed to be built from a BoardLayout (target geometry) and an optional scale prior. Three recommended constructors cover the common cases:

#![allow(unused)]
fn main() {
use ringgrid::{BoardLayout, DetectConfig, MarkerScalePrior};
use std::path::Path;

let board = BoardLayout::from_json_file(Path::new("board_spec.json")).unwrap();

// 1. Default scale prior (14--66 px diameter range)
let cfg = DetectConfig::from_target(board.clone());

// 2. Explicit scale range
let scale = MarkerScalePrior::new(24.0, 48.0);
let cfg = DetectConfig::from_target_and_scale_prior(board.clone(), scale);

// 3. Fixed marker diameter hint (min == max)
let cfg = DetectConfig::from_target_and_marker_diameter(board.clone(), 32.0);
}

All three constructors call two internal derivation functions:

  • apply_target_geometry_priors – derives marker_spec.r_inner_expected and decode.code_band_ratio from the board’s inner/outer radius ratio.
  • apply_marker_scale_prior – derives proposal radii, edge sampling range, ellipse validation bounds, completion ROI, and projective-center shift gate from the scale prior. See MarkerScalePrior for the full derivation rules.

The Detector wrapper

Most users interact with DetectConfig through the Detector struct, which wraps a config and exposes detection methods:

#![allow(unused)]
fn main() {
use ringgrid::{BoardLayout, Detector, MarkerScalePrior};
use std::path::Path;

let board = BoardLayout::from_json_file(Path::new("board_spec.json")).unwrap();

// Convenience constructors mirror DetectConfig
let det = Detector::new(board.clone());                           // default scale
let det = Detector::with_marker_scale(board.clone(),
              MarkerScalePrior::new(24.0, 48.0));                 // explicit range
let det = Detector::with_marker_diameter_hint(board.clone(), 32.0); // fixed size

// One-step from JSON file
let det = Detector::from_target_json_file(Path::new("board_spec.json")).unwrap();

// Full config control
let cfg = DetectConfig::from_target(board);
let det = Detector::with_config(cfg);

// Detect
let result = det.detect(&image);

// Adaptive multi-scale APIs (wide size variation scenes)
let result = det.detect_adaptive(&image);
let result = det.detect_adaptive_with_hint(&image, Some(32.0));
}

Post-construction tuning

After building a Detector, use config_mut() to override individual fields:

#![allow(unused)]
fn main() {
let mut det = Detector::new(board);
det.config_mut().completion.enable = false;
det.config_mut().use_global_filter = false;
det.config_mut().self_undistort.enable = true;
}

Calling set_marker_scale_prior() or set_marker_diameter_hint_px() on DetectConfig re-derives all scale-coupled parameters automatically.

Field reference

FieldTypeDefaultPurpose
marker_scaleMarkerScalePrior14.0–66.0 pxExpected marker diameter range in pixels. Drives derivation of many downstream parameters.
outer_estimationOuterEstimationConfig(see sub-configs)Outer-edge radius hypothesis generation from radial profile peaks.
proposalProposalConfig(derived from scale)Scharr gradient voting and NMS proposal generation. r_min, r_max, nms_radius are auto-derived.
seed_proposalsSeedProposalParamsmerge=3.0, score=1e12, max=512Controls seed injection for multi-pass detection.
edge_sampleEdgeSampleConfig(derived from scale)Radial edge sampling range and ray count. r_min, r_max are auto-derived.
decodeDecodeConfig(derived from board)16-sector code sampling. code_band_ratio is auto-derived from board geometry; codebook_profile defaults to base.
marker_specMarkerSpec(derived from board)Marker geometry specification. r_inner_expected is auto-derived from board inner/outer radius ratio.
inner_fitInnerFitConfig(see sub-configs)Robust inner ellipse fitting: RANSAC params, validation gates.
circle_refinementCircleRefinementMethodProjectiveCenterCenter correction strategy selector: None or ProjectiveCenter.
projective_centerProjectiveCenterParams(see sub-configs)Projective center recovery gates and tuning. max_center_shift_px is auto-derived from scale.
completionCompletionParams(see sub-configs)Completion at missing H-projected board positions. roi_radius_px is auto-derived from scale.
min_semi_axisf643.0Minimum semi-axis length (px) for a valid outer ellipse. Auto-derived from scale.
max_semi_axisf6415.0Maximum semi-axis length (px) for a valid outer ellipse. Auto-derived from scale.
max_aspect_ratiof643.0Maximum aspect ratio (a/b) for a valid ellipse.
dedup_radiusf646.0NMS deduplication radius (px) for final markers.
use_global_filterbooltrueEnable RANSAC homography global filter (requires board layout with marker positions).
ransac_homographyRansacHomographyConfigiters=2000, thresh=5.0RANSAC parameters for homography estimation.
boardBoardLayoutemptyBoard layout defining marker positions and geometry.
id_correctionIdCorrectionConfigenabledStructural consistency verification/recovery of decoded IDs before global filter.
self_undistortSelfUndistortConfigdisabledSelf-undistort estimation from conic consistency of detected ring edges.

Fields marked “auto-derived” are overwritten by the constructors. If you modify marker_scale after construction, call set_marker_scale_prior() to re-derive them.

Source

crates/ringgrid/src/detector/config.rs, crates/ringgrid/src/api.rs