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

Pipeline Overview

The ringgrid detection pipeline transforms a grayscale image into a set of identified marker detections with sub-pixel centers, fitted ellipses, decoded IDs (coded targets) or lattice coordinates (plain targets), and an optional board-to-image homography. The pipeline is structured in two major phases executed in sequence: fit-decode, then a grid-first finalize.

Coded and plain (uncoded) targets share one finalize back half: every fitted ring is labeled by the lattice, and the labeling is anchored to the board by decoded IDs (coded) or origin dots (plain). Which combinations run which path is summarized in the target composition matrix.

Supported scene: one board per image. With a second board of any layout in view, rings of the other board can be labeled into this one; the detector does not guard against it.

Every reported marker carries a confidence that predicts how far its centre can be trusted (rim coverage and inner-edge agreement for an edge-fitted centre, the fit’s own centre covariance for a photometric one; outer-edge sharpness, distance to the image border, decode/fit evidence); DetectConfig::min_confidence (default 0.03) drops the markers below it on the finished result — the one knob trading recall for centre accuracy.

Two-Phase Architecture

Phase 1: Fit-Decode

Orchestrated by pipeline/fit_decode.rs, this phase takes raw proposals and produces individually decoded markers:

StageNameDescription
1ProposalScharr gradient voting + NMS produces candidate centers
2Outer EstimateRadial profile peak detection yields radius hypotheses
3Outer FitRANSAC ellipse fitting on sampled edge points
4Decode16-sector code sampling and codebook matching
5Inner EstimateInner ring ellipse fitting from outer prior
6DedupSpatial and ID-based deduplication

Stages 2–5 are executed per-proposal inside process_candidate(). A proposal that fails at any stage is rejected with a diagnostic reason string. Successfully built markers are collected, then deduplicated in stage 6.

Phase 2: Finalize

Orchestrated by the pipeline/finalize/ module (grid.rs), this phase applies global geometric reasoning to identify, extend and verify the detection set:

OrderNameDescription
1Projective CenterCorrect fit-decode marker centers (once per marker)
2Grid labelingLabel every fitted ring — decoded or not — with lattice coordinates (pipeline/assign.rs)
3Anchor + identifyDecoded IDs vote for the board placement (coded) or origin dots verify it (plain); every labeled ring takes its cell’s ID, overriding a contradicting decode (pipeline/anchor.rs)
4CompletionDecoded dropped rings join through a RANSAC homography; completion grows from the labeled patch, adopting already-fitted rings before refitting missing cells
5Final H RefitRefit homography from all labeled markers
6Geometric VerifyPrecision-first lattice-consistency gate; removes geometrically impossible markers

When no grid can be labeled (coded targets: or anchored), coded views fall back to the decode-anchored path (finalize/fallback.rs): ID Correction (hex targets), a RANSAC global filter over decoded markers, completion, final H and verify; with fewer than six consistent decodes the decoded markers are returned without a homography. Plain views without a grid return their markers unlabeled.

When use_global_filter is false, finalize runs projective center correction and returns the markers without labeling or homography.

With circle_refinement = Photometric (opt-in), photometric center refinement runs after finalize, once per detection call on the finished result, and the final homography is then refit from the refined centers. Geometric verification then runs there, on the refined centers, instead of inside finalize (see below).

Geometric Verification

After the final homography, a precision-first gate (pipeline/geometric_verify.rs, enabled by advanced.geometric_verify, default true) checks every labeled marker against the target lattice and removes the geometrically inconsistent ones, so only trusted board correspondences reach the output. Two complementary tests run, rejecting on their union:

  1. Global final-H reprojection (gross-blunder backstop) and an ellipse-shape test: each marker’s center versus its board position projected through the final homography, and its outer ellipse’s axis ratio versus the one the homography predicts at its cell.
  2. Local lattice-midpoint (distortion-robust primary), on the markers the global tests keep: each marker’s deviation from the final homography versus the midpoint of its lattice neighbors’ deviations. A second difference of what the homography cannot explain, so perspective cancels and it sees only the curvature of smooth lens distortion, while a wrong-cell marker sits ~1 pitch off. Corner markers without an opposite pair are tested one-sided; a labeled marker with no labeled neighbor is removed when distortion has loosened the global threshold past half a cell pitch. Without a homography the centers themselves are compared.

With photometric refinement the gate runs after the photometric stage, on the refined centers and against the homography that best fits the photometric centers: an edge-fitted center of a blurred, eccentric ring is biased by 2–3 px, beyond the 2 px floors, while its photometric center is not.

Both thresholds adapt to the observed inlier-residual distribution (max(floor, median + k·MAD)), so the gate stays recall-safe on clean and distorted boards alike. It is lattice-generic and coordinate-keyed, so it applies to coded and plain targets identically. See Detection Quality & Rejection.

Plain-Target Path

Plain (uncoded) rings carry no IDs; they run the same grid-first back half (pipeline/finalize/grid.rs), anchored by the origin dots instead of decoded IDs. The full walkthrough — grid assignment, origin resolution, completion, and the absolute/relative frame contract — is on its own page: Plain / Rect Target Detection.

Projective Center Correction

Projective center correction recovers the true projected center of a ring marker from its inner and outer ellipse pair, compensating for the perspective bias inherent in ellipse center estimation. It is applied once per marker at two points in the pipeline:

  1. Before grid labeling: Corrects all fit-decode markers so that downstream geometric stages operate on unbiased centers.
  2. After completion: Newly added completion markers receive their own correction. Only the slice of markers added since the last correction is processed.

Each marker is corrected exactly once. apply_projective_centers() from detector/center_correction.rs requires both inner and outer ellipses. Markers without a valid inner ellipse are skipped.

Pipeline Entry Points

All detection is accessed through the Detector struct in api.rs, which delegates to the entry points in pipeline/run.rs:

detect_single_pass

The simplest mode. Runs proposal generation followed by the full fit-decode and finalize pipeline without any pixel mapper:

proposals = find_proposals(gray, config)
fit_markers = fit_decode::run(gray, config, None, proposals)
result = finalize::run(gray, fit_markers, config, None)

detect_with_mapper

Two-pass detection with an external pixel mapper (e.g., from known camera intrinsics):

  1. Pass 1: Run detect_single_pass without the mapper to get initial detections.
  2. Pass 2: Extract seed proposals from pass-1 detections, then re-run the full pipeline with the mapper active.

The mapper transforms between image pixel coordinates and a distortion-corrected “working” coordinate frame. During pass 2, edge sampling and decoding operate in working space, producing more accurate fits under lens distortion. Final marker centers are mapped back to image space; the homography lives in the working frame.

Self-undistort (detect with self_undistort.enable)

There is no separate entry point: Detector::detect runs this flow when config.self_undistort.enable is set. It estimates a division-model distortion correction from the detected markers, then optionally re-runs detection with the estimated mapper:

  1. Baseline pass: Run detect_single_pass.
  2. Self-undistort estimation: If enabled and enough markers with edge points are available, estimate a DivisionModel mapper from the ellipse edge points.
  3. Pass 2 (conditional): If estimation succeeded, re-run as a seeded pass-2 with the estimated mapper.

The self-undistort result is attached to DetectionResult.self_undistort regardless of whether pass 2 was applied.

detect_adaptive and detect_multiscale

Adaptive scale entry points run the same fit/decode and finalize logic, but over one or more scale tiers:

  1. Build tiers (automatic probe, hint-derived, or explicit).
  2. Run per-tier fit/decode + projective center.
  3. Merge markers across tiers with size-aware dedup.
  4. Run grid labeling + anchoring + completion + final homography refit once.

detect_adaptive runs several such tier candidates, keeps the best and joins in the anchored markers of the others at cells it lacks, or at cells where its own marker would not be reported (no corrected centre, below min_confidence) and the other candidate’s would. See Adaptive Scale Detection.

Seed Injection in Two-Pass Modes

When a pass-2 runs (either detect_with_mapper or self-undistort via detect), the pass-1 detection centers become the pass-2 proposals — pass 2 does not re-run the gradient proposal stage. Seeds are ordered by pass-1 marker confidence (each seed’s score is that confidence). The SeedProposalConfig configuration controls:

  • max_seeds: Optional cap on the number of seeds consumed (default: 512).

Coordinate Frames

The pipeline maintains two coordinate frames:

  • Image frame: Raw pixel coordinates in the input image.
  • Working frame: Distortion-corrected coordinates when a PixelMapper is active; identical to image frame when no mapper is present.

Edge sampling, ellipse fitting, decoding, and homography estimation all operate in the working frame. The final DetectedMarker.center is always in image space. When a mapper is active, center_mapped preserves the working-frame center, and homography_frame is set to DetectionFrame::Working.

Output Structure

The pipeline produces a DetectionResult containing:

  • detected_markers: The final list of DetectedMarker structs.
  • homography: Optional 3x3 board-to-image homography matrix.
  • ransac: Optional RansacStats for the homography fit.
  • image_size: Dimensions of the input image.
  • center_frame: Always DetectionFrame::Image.
  • homography_frame: Image or Working depending on mapper presence.
  • self_undistort: Optional self-undistort estimation result.

For the serialized JSON shape used by the CLI and examples, see Detection Output Format.

Source: pipeline/run.rs, pipeline/fit_decode.rs, pipeline/finalize/ (grid.rs, fallback.rs, common.rs), pipeline/assign.rs, pipeline/anchor.rs, pipeline/geometric_verify.rs