CLI Guide
The published ringgrid command-line tool generates calibration targets from a
recipe and detects them in images. Install it with:
cargo install ringgrid --features cli
This produces a ringgrid binary on your PATH. (Library users add the crate
with cargo add ringgrid; Python users pip install ringgrid.)
The binary has five subcommands:
ringgrid gen <recipe.toml> --out DIR # printable target artifacts
ringgrid gen-screen <template> --width-px W --height-px H \
--pixel-pitch-mm P --marker-diameter-mm D --out DIR
# grayscale target for a display
ringgrid detect --image P --target T --out J # one image
ringgrid batch --images DIR --target T --out-dir D
ringgrid example --list | --name NAME [--out FILE]
Recipes
gen (and detect/batch, which also accept one) read a recipe — a small
TOML or JSON file describing the target. The CLI lowers the recipe to a
TargetLayout and renders it.
name = "lab_hex_coded"
coding = { kind = "coded" } # or { kind = "plain" }
fiducials = "none" # "none" | "auto" | { dot_radius_mm = .. }
[lattice]
kind = "hex" # "hex" (rows, long_row_cols, pitch_mm)
rows = 15 # or "rect" (rows, cols, pitch_mm)
long_row_cols = 14
pitch_mm = 8.0
[marker]
outer_radius_mm = 4.8
inner_radius_mm = 3.2
ring_width_mm = 1.152 # required only for coded markers
[render]
dpi = 300
formats = ["json", "svg", "png", "dxf"]
[render.page] # omit for a square page fitted to the content
margin_mm = 5.0
The top-level scalar keys (name, coding, fiducials) must precede the
[lattice] / [marker] / [render] tables — a TOML requirement. Recipes cover
the six valid combinations of {hex, rect} × {coded, plain} ×
{origin dots, no dots}; the one excluded combination is coded markers
(coding = { kind = "coded" }) with fiducials, which is rejected (coded markers already carry identity). See
Target Generation for every field and all six examples.
ringgrid example — list or emit built-in recipes
Built-in recipes ship inside the binary, so you never need a repository checkout.
# List the built-in recipe names
ringgrid example --list
# Print a recipe to stdout
ringgrid example --name hex_coded
# Write a recipe to a file to edit and feed to `gen`
ringgrid example --name rect_plain_dots --out rect_plain_dots.toml
The available names are hex_coded, rect_coded, hex_plain_dots,
hex_plain_nodots, rect_plain_dots, and rect_plain_nodots.
ringgrid gen — generate target artifacts
Reads a recipe and writes target_spec.json (schema ringgrid.target.v6) plus
the printable <basename>.svg, .png, and .dxf to the output directory.
ringgrid gen hex_coded.toml --out ./out/target
| Flag | Default | Description |
|---|---|---|
<recipe> | required | Recipe file (.toml or .json) — positional argument. |
--out <dir> | out | Output directory (created if absent). |
--basename <name> | target_print | Base filename for the SVG/PNG/DXF outputs. |
--name <n> | recipe value | Override the target name. |
--pitch-mm <x> | recipe value | Override the lattice pitch (mm). |
--dpi <x> | recipe value | Override the PNG resolution (dpi). |
--margin-mm <x> | recipe value | Override the print margin (mm). |
--formats <list> | recipe value | Override the emitted formats (comma-separated: json,svg,png,dxf). |
CLI flags override the corresponding recipe fields.
ringgrid gen-screen — fit a target to a screen
Builds a target for one display: it scales a template target to the requested
marker diameter, fits the grid with the most markers on the screen, and renders
a native-resolution grayscale PNG for 1:1 display. Writes target_screen.png,
target_spec.json (the fitted target, for detect --target) and
screen.json (the fit and the board-to-screen pixel mapping).
ringgrid gen-screen hex_coded.toml \
--width-px 825 --height-px 1200 --pixel-pitch-mm 0.16933333333333334 \
--marker-diameter-mm 10.752 --out ./out/screen
| Flag | Default | Description |
|---|---|---|
<template> | required | Target spec or recipe — positional. Supplies lattice kind, marker proportions, coding and origin dots; its size is ignored. |
--out <dir> | out | Output directory (created if absent). |
--width-px <n> | required | Native screen width in pixels, in the orientation you will display it. |
--height-px <n> | required | Native screen height in pixels. |
--pixel-pitch-mm <x> | required | Physical size of one display pixel in mm (25.4 / ppi, or measured active width / width-px). |
--marker-diameter-mm <x> | required | Drawn outer marker diameter in mm, including the outer ring stroke. |
--margin-px <n> | 8 | Minimum white margin on each edge, in display pixels. |
It prints the fitted marker count and the realized marker diameter and code-band width in display pixels; the command fails when not even a 2 × 2 grid fits. Why the PNG is grayscale, how the fit works and how to choose the diameter are in Target Generation → Screen targets.
ringgrid detect — detect markers in an image
Loads an image, runs the detection pipeline against a target, and writes the result JSON.
ringgrid detect \
--image photo.png \
--target target_spec.json \
--out result.json
| Flag | Default | Description |
|---|---|---|
--image <path> | required | Input image file. |
--target <path> | required | Target spec (target_spec.json) or a recipe (.toml/.json). |
--out <path> | stdout | Output JSON path. When omitted, the result JSON is printed to stdout. |
--marker-diameter <px> | auto | Approximate marker outer diameter (px) for focused single-pass detection. |
--config <path> | none | Detection-config overlay (.json/.toml) — see Configuration. |
--strict | false | Require the complete board: fail unless every cell is detected. |
--refine <method> | from config | Center refinement: none, projective-center or photometric (overrides the --config overlay’s circle_refinement). |
--strict maps onto the same require_complete_board gate that plain targets
without origin dots rely on (their identity comes from detecting the whole
board). --refine photometric selects the blur-robust
photometric center refinement
(opt-in: it costs milliseconds per marker). Fine-grained detection behavior —
scale prior, RANSAC thresholds, completion gates — is set through the
--config overlay rather than dedicated flags; see
Configuration.
ringgrid batch — detect across a directory
Runs detection on every image in a directory, writing one <stem>.json per
image plus an aggregate summary.json.
ringgrid batch \
--images ./captures \
--target target_spec.json \
--out-dir ./out/batch
| Flag | Default | Description |
|---|---|---|
--images <dir> | required | Directory of input images. |
--target <path> | required | Target spec or recipe. |
--out-dir <dir> | required | Directory for per-image <stem>.json results (created if absent). |
--summary <path> | <out-dir>/summary.json | Aggregate summary path. |
--marker-diameter <px> | auto | Approximate marker outer diameter (px). |
--config <path> | none | Detection-config overlay (.json/.toml). |
--strict | false | Require the complete board on every image. |
--refine <method> | from config | Center refinement: none, projective-center or photometric. |
The summary.json records, per image, the marker count, decoded count, and
board_complete flag.
Logging
ringgrid uses the tracing crate for structured logging. Control verbosity with
the RUST_LOG environment variable:
# Default level (info) -- shows summary statistics
ringgrid detect --image photo.png --target target_spec.json --out result.json
# Debug level -- shows per-stage diagnostics
RUST_LOG=debug ringgrid detect --image photo.png --target target_spec.json --out result.json
# Trace level -- shows detailed per-marker information
RUST_LOG=trace ringgrid detect --image photo.png --target target_spec.json --out result.json
At the default info level, the detector logs image dimensions, the loaded
target, detected and decoded marker counts, homography statistics, and the
output path.
Output Format
ringgrid detect writes the serialized DetectionResult fields at the top
level:
detected_markerscenter_framehomography_frameimage_size- optional
homographyandself_undistort - a nested
diagnosticsobject carrying per-marker algorithm internals (diagnostics.markers) and homography RANSAC statistics (diagnostics.ransac)
The full file shape, nested marker fields, and frame semantics are documented in Output Format.
Adaptive scale
Adaptive multi-scale detection is exposed through the Rust and Python libraries (not the published CLI, which uses the regular config-driven flow):
Detector::detect_adaptiveDetector::detect_adaptive_with_hintDetector::detect_multiscale
The Python bindings expose the same concepts on ringgrid.Detector. See
Adaptive Scale Detection.
Developing ringgrid. The repository also ships an in-repo development binary,
ringgrid-dev, with maintainer-only subcommands (codebook-info,board-info,decode-test, and the legacygen-targetfamily) and a repository checkout is required. Run it withcargo run -p ringgrid-cli --bin ringgrid-dev -- <subcommand>. See Development.
Source Files
- Published binary:
crates/ringgrid/src/bin/ringgrid.rs - CLI support (recipes, artifacts, detect):
crates/ringgrid/src/cli/