Skip to main content

calib-targets — Python bindings

Book

Native-feeling Python API for the calib-targets Rust workspace. Detects chessboards, ChArUco, PuzzleBoard, PuzzlePole, and marker boards, and generates printable target bundles (JSON + SVG + PNG + DXF). Built with PyO3 + maturin.

Python package name: calib_targets (the Rust crate is calib-targets-py).

Install

# From source — this repo:
uv pip install maturin
uv run maturin develop --release -m crates/calib-targets-py/Cargo.toml

# Or from PyPI (pre-built wheels):
pip install calib-targets

Hello world

import numpy as np
from PIL import Image
import calib_targets as ct

image = np.asarray(Image.open("board.png").convert("L"), dtype=np.uint8)
result = ct.detect_chessboard_best(image, [ct.ChessboardParams()])
if result is not None:
    print(f"labelled {len(result.corners)} corners")

End-to-end round-trip per target type

Each snippet covers: generate a printable target → load the PNG → detect → export detection to JSON.

Runnable scripts at crates/calib-targets-py/examples/. Use any of them as a starting point.

Chessboard

import io, json
import numpy as np
from PIL import Image
import calib_targets as ct

# 1. Generate target.
doc = ct.PrintableTargetDocument(
    target=ct.ChessboardTargetSpec(inner_rows=7, inner_cols=9, square_size_mm=20.0),
    page=ct.PageSpec(size=ct.PageSize.custom(width_mm=220.0, height_mm=180.0), margin_mm=10.0),
    render=ct.RenderOptions(png_dpi=150),
)
bundle = ct.render_target_bundle(doc)

# 2. Load as grayscale numpy array.
image = np.asarray(Image.open(io.BytesIO(bundle.png_bytes)).convert("L"), dtype=np.uint8)

# 3. Detect — prefer *_best for robustness.
chess_cfg = ct.ChessConfig(threshold=15.0)
configs = [
    ct.ChessboardParams(),
    ct.ChessboardParams(min_labeled_corners=12),
    ct.ChessboardParams(max_components=1),
]
result = ct.detect_chessboard_best(image, configs, chess_cfg=chess_cfg)

# 4. Export detection to JSON.
print(json.dumps(result.to_dict(), indent=2)[:200])

Runnable: examples/chessboard_roundtrip.py.

ChArUco

import calib_targets as ct
# (synthesise PNG as above; build matching board spec)
board = ct.CharucoBoardSpec(
    rows=5, cols=7, cell_size=1.0, marker_size_rel=0.75,
    dictionary="DICT_4X4_50", marker_layout=ct.MarkerLayout.OPENCV_CHARUCO,
)
params = ct.CharucoParams(
    board=board, px_per_square=60.0,
    chessboard=ct.ChessboardParams(),
    min_marker_inliers=4,
)
result = ct.detect_charuco(image, params=params)   # None when no board is found
if result is not None:
    print(len(result.corners), "corners,", len(result.markers), "markers")

Runnable: examples/charuco_roundtrip.py.

Marker board

circles = (
    ct.MarkerCircleSpec(i=3, j=2, polarity=ct.CirclePolarity.WHITE),
    ct.MarkerCircleSpec(i=4, j=2, polarity=ct.CirclePolarity.BLACK),
    ct.MarkerCircleSpec(i=4, j=3, polarity=ct.CirclePolarity.WHITE),
)
board = ct.MarkerBoardSpec(rows=6, cols=8, cell_size=1.0, circles=circles)
params = ct.MarkerBoardParams(board=board, chessboard=ct.ChessboardParams())
result = ct.detect_marker_board(image, params=params)

MarkerBoardSpec is also exported under its previous name MarkerBoardLayout (a backward-compatible alias that stays live this release).

Runnable: examples/markerboard_roundtrip.py.

PuzzleBoard

params = ct.default_puzzleboard_params(rows=10, cols=10)
params.decode.search_mode = ct.PuzzleBoardSearchMode.fixed_board()
params.decode.scoring_mode = ct.PuzzleBoardScoringMode.soft_log_likelihood()
params.decode.symmetry_mode = ct.PuzzleBoardSymmetryMode.rotations()  # default
result = ct.detect_puzzleboard(image, params=params)
# Every corner has an absolute master ID: result.corners[0].id
# Soft-mode scoring evidence is available from diagnose_puzzleboard().

Runnable: examples/puzzleboard_roundtrip.py.

PuzzlePole

The PuzzleBoard pattern wrapped round a cylinder (Zach & Stelldinger 2025, arXiv:2511.19448), so the target is identifiable from a full 360°. It is the only family here whose corners carry a 3-D object point.

# The circumference must be a period that closes seamlessly -- see
# ct.supported_puzzlepole_periods(). The diameter follows from it.
pole = ct.PuzzlePoleSpec.canonical(24, 12, 20.0)      # 152.8 mm across
result = ct.detect_puzzlepole(image, params=ct.PuzzlePoleParams.for_pole(pole))

for image_point, object_point in result.correspondences():
    ...  # (u, v) px  ->  (x, y, z) mm on the cylinder

Hand those pairs to cv2.solvePnP with SOLVEPNP_SQPNP, which does not assume coplanar points. This library produces the correspondences and stops there.

Two runnable tools cover the whole loop:

# the strip to print and wrap -- the page is sized to it, since a useful
# pole does not fit A4 and the renderer refuses rather than rescaling
python examples/generate_printable_puzzlepole.py --list --square-size-mm 20
python examples/generate_printable_puzzlepole.py --out-stem out/pole24 \
    --circumference-squares 24 --axial-squares 12 --square-size-mm 20

# detect it: overlay to look at, CSV to calibrate from, pose if you have
# intrinsics. --doc reads the pole back out of the generated document, which
# beats retyping it -- a spec off by one column still decodes, wrongly.
python examples/detect_puzzlepole.py view.png --doc out/pole24.json \
    --overlay seen.png --csv pairs.csv --pnp --fx 1050 --cx 260 --cy 350

Runnable: examples/generate_printable_puzzlepole.py, examples/detect_puzzlepole.py (--pnp needs OpenCV; nothing else does).

Inputs

  • image: numpy.ndarray[uint8] with shape (h, w). Grayscale only; convert RGB upstream (Image.convert("L")).
  • chess_cfg: ChessConfig | None — overrides the default ChESS corner detector.
  • params: *Params — typed dataclass matching the detector. Dict inputs are rejected; use the typed classes.

Outputs

Every detect_* function returns None when the image holds no board it can identify, and raises ValueError only on a misuse — a malformed image, an invalid board spec or invalid parameters.

Every detection result is a typed dataclass with full attribute access, editor autocomplete, and type stubs. Round-trip through JSON with to_dict() and from_dict(...) — the dict schema matches the Rust crate's serde_json output byte-for-byte.

payload = json.dumps(result.to_dict())
# ... later, elsewhere:
restored = ct.ChessboardDetectionResult.from_dict(json.loads(payload))

Every config / result type has these methods — ChessConfig, ChessboardParams, CharucoParams, PuzzleBoardParams, PuzzlePoleParams, MarkerBoardParams, PrintableTargetDocument, and all result types.

Printable targets

One-liner helpers with sensible defaults (A4 portrait, 10 mm margins, 300 DPI):

doc = ct.charuco_document(rows=5, cols=7, square_size_mm=20.0,
                          marker_size_rel=0.75, dictionary="DICT_4X4_50")
written = ct.write_target_bundle(doc, "out/charuco_a4")
print(written.json_path, written.svg_path, written.png_path, written.dxf_path)

Other helpers: chessboard_document, puzzleboard_document, puzzlepole_document, marker_board_document. Each accepts optional page= / render= overrides. For full control, construct PrintableTargetDocument directly with one of the target specs (ChessboardTargetSpec, CharucoTargetSpec, MarkerBoardTargetSpec, PuzzleBoardTargetSpec, PuzzlePoleTargetSpec).

A PuzzlePole is the one family whose page cannot be left at the A4 default: its strip is circumference + 2 pieces tall, which overflows the sheet at any useful piece size, and the renderer raises rather than rescaling. Size the page to the strip, or let examples/generate_printable_puzzlepole.py do it.

CLI

pip install calib-targets installs a calib-targets console script that mirrors the Rust CLI:

calib-targets gen puzzleboard --rows 8 --cols 10 --square-size-mm 15 \
    --out-stem puzzle
calib-targets list-dictionaries
calib-targets init chessboard --out spec.json \
    --inner-rows 6 --inner-cols 8 --square-size-mm 20
calib-targets generate --spec spec.json --out-stem my_board

For grayscale displays, use calib-targets gen-screen or call render_screen_target(target, ScreenTargetOptions(width_px, height_px, pixel_pitch_mm)). Use the returned metadata to set the physical square size and marker ratio for detection. Screen-target tutorial

See testdata/printable/*.json for ready-made spec files; every file is PrintableTargetDocument.from_dict( json.load(open(path)))-compatible.

Tuning difficult cases

  1. Replace detect_* with detect_*_best and pass the matching sweep preset — ChessboardParams.sweep_default(), CharucoParams.sweep_for_board(board), MarkerBoardParams.sweep_for_board(board) or PuzzleBoardParams.sweep_for_board(board). Each preset is computed by Rust and handed to Python, so both language surfaces search the same configuration space. This is the recommended default.
  2. Increase rasterisation / input resolution if cells are smaller than ~20 px across.
  3. Open the per-detector README for deeper guidance: chessboard, ChArUco, PuzzleBoard, marker. Python passes all parameters through to Rust, so tuning advice applies identically.

Limitations

  • One target instance per image. Multiple simultaneous boards are not detected; pass cropped sub-images per target.
  • Pinhole-ish optics only. Moderate radial / perspective distortion is handled gracefully; fisheye is not supported.
  • Grayscale uint8 numpy arrays only. No torch tensors, no GPU.
  • Board PNG / SVG generation for chessboard, ChArUco, marker board, and PuzzleBoard is supported; other target kinds are not.

Feature parity vs Rust facade

  • detect_chessboard / _all / _best / _debug — ✔
  • detect_charuco / _with_corners / _best, detect_puzzleboard / _with_corners / _best, detect_marker_board / _with_corners / _best — ✔
  • diagnose_charuco / _with_corners, diagnose_puzzleboard / _with_corners, diagnose_marker_board / _with_corners — ✔
  • Printable targets for all four target kinds — ✔
  • to_dict / from_dict round-trip on every config + result type — ✔

Reusing a corner cloud across detectors

Each of ChArUco, PuzzleBoard, and marker board runs its own ChESS corner pass from params.chess inside detect_*. The _with_corners variant skips that pass and takes a corner cloud directly — useful when several detectors should share one pass, or the corners come from a custom upstream:

corners = ct.trace_chessboard_topological(image, params=None)["corners"]
result = ct.detect_charuco_with_corners(image, corners, params=params)

corners is a list of ChessCorner-shaped dicts: {"position": [x, y], "position_covariance": {...} | None, "axes": [...], "strength": ...} (position_covariance may be omitted).

Per-corner position covariance

Every corner type (LabeledCorner, ChessboardCorner, CharucoCorner, PuzzleBoardCorner, PuzzlePoleCorner, MarkerBoardCorner) carries position_covariance: PositionCovariance | None — the covariance of position in px², image frame (xx, xy, yy; as_matrix(), sigma_max_px()). It is off by default; switch it on with ChessConfig(uncertainty=Uncertainty.propagated()), or Uncertainty.propagated(noise_sigma=σ) with a known sensor noise in gray levels.

It is None when none was measured: the uncertainty is off (the default), an upscale stage is active, or the frame's noise estimate declined — typical of JPEG input; supply noise_sigma then. Positions do not depend on it. Model and caveats: chess-corners, Part VIII: Uncertainty.

Per-detection quality

Every detection result (ChessboardDetectionResult, CharucoDetection, PuzzleBoardDetection, PuzzlePoleDetection, MarkerBoardDetection) has a quality: DetectionQuality field (every optional field None when unavailable; a PuzzlePole carries the covariance statistics only):

Field Meaning
noise_sigma Image noise (gray levels) the covariances used; None when the uncertainty is off (the default), for *_with_corners calls, or when the estimate declined.
covariance_coverage Fraction of delivered corners carrying a covariance.
median_sigma_px, p95_sigma_px Median / 95th-percentile per-corner σ (least certain direction), px.
local_residual_count, local_residual_rms_px Corners with ≥ 6 of 8 grid neighbours; RMS of their leave-one-out residual (corner predicted from its neighbours alone), px.
variance_factor_count, variance_factor Robust variance factor σ̂₀² of those residuals whitened by the corner's and the prediction's covariance: ≈ 1 the covariances describe the local scatter, > 1 overconfident (expected on real images). Frame-comparable, not pass/fail.

See the book's Corner uncertainty & detection quality page.

Implementation note

The compiled Rust module is internal (calib_targets._core). Public API stability is guaranteed only for top-level calib_targets exports.

Metadata

Release files for calib-targets 0.16.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for calib-targets 0.16.3
File Size Uploaded Provenance Actions
calib_targets-0.16.3.tar.gz 985.2 kB With provenance Details for calib_targets-0.16.3.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for calib-targets 0.16.3
File Interpreter ABI Platform Actions
calib_targets-0.16.3-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for calib_targets-0.16.3-cp310-abi3-win_amd64.whl
calib_targets-0.16.3-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for calib_targets-0.16.3-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
calib_targets-0.16.3-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for calib_targets-0.16.3-cp310-abi3-macosx_11_0_arm64.whl

Total release size: 5.7 MB

Release files / calib_targets-0.16.3.tar.gz

Download URL calib_targets-0.16.3.tar.gz
Size 985.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d97c925664f4563b1e0722aaa34015b85e63c8ca8b1c4d735980a2351046b281
BLAKE2b-256 checksum
How to use checksums
f73f056520ba3cf92666df8306791052e21259b7a801edb222640a89a081f224
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / calib_targets-0.16.3-cp310-abi3-win_amd64.whl

Download URL calib_targets-0.16.3-cp310-abi3-win_amd64.whl
Size 1.4 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
ce9e09a18d92d4fd1c894fc423865ac2a429dd2be055e90bee8fc475476834e8
BLAKE2b-256 checksum
How to use checksums
906f13be759a3ae9ee28dd662ba651a2357efa3df73216fa08864cf42cf1e7c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / calib_targets-0.16.3-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL calib_targets-0.16.3-cp310-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.7 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
8d27ca04b09f5aeb906986dd24917d18ba97268009b581e4c49489ab53abe8b7
BLAKE2b-256 checksum
How to use checksums
ae463d4f2df9582509ea4d74766cc8588958b991c9bf438c5226df87c80519f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Release files / calib_targets-0.16.3-cp310-abi3-macosx_11_0_arm64.whl

Download URL calib_targets-0.16.3-cp310-abi3-macosx_11_0_arm64.whl
Size 1.5 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
b65fc63db939f5846e9e87b9e7e142a94df703d30c6726b43edf9bd4c931d9d4
BLAKE2b-256 checksum
How to use checksums
c3210ddff5a89fc770b4dfbebbf0829d9b103f6306835faf7e0a3daff2fbc3de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

Security for calib-targets 0.16.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for calib_targets-0.16.3.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.16.3 This release

4 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page