API Reference
This page provides detailed information about the Locus Python API.
Core Interface
The primary entry point is the Detector class. It can be initialized with various configuration parameters passed as keyword arguments.
import locus
# Initialize with keyword arguments
detector = locus.Detector(
families=[locus.TagFamily.AprilTag36h11, locus.TagFamily.ArUco4x4_50],
decimation=2,
threads=4,
)
batch = detector.detect(img)
locus.Detector
High-level detector.
Construction
Detector(profile="standard") — load a shipped JSON profile by name.
Detector(config=my_cfg) — use a pre-built :class:DetectorConfig.
Detector() — equivalent to profile="standard".
Per-call orchestration options (decimation, threads, families)
stay outside the profile because they describe how the detector is
invoked, not what it looks for.
Source code in crates/locus-py/locus/__init__.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
Functions
__init__
__init__(profile: ProfileName | None = None, config: DetectorConfig | None = None, *, decimation: int | None = None, threads: int | None = None, families: list[TagFamily] | None = None) -> None
Source code in crates/locus-py/locus/__init__.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
detect
detect(img: ndarray, intrinsics: CameraIntrinsics | None = None, tag_size: float | None = None, debug_telemetry: bool = False, **kwargs) -> DetectionBatch
Detect tags in the image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
img
|
ndarray
|
Input grayscale image (np.uint8). |
required |
intrinsics
|
CameraIntrinsics | None
|
Optional CameraIntrinsics for 3D pose estimation. |
None
|
tag_size
|
float | None
|
Optional physical tag size (meters). |
None
|
Returns:
| Type | Description |
|---|---|
DetectionBatch
|
A vectorized DetectionBatch object. |
Source code in crates/locus-py/locus/__init__.py
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |
Concurrent Detection
Detector supports concurrent multi-frame processing via detect_concurrent. To configure the internal pool size (max_concurrent_frames), you must use the DetectorBuilder.
See the Concurrent Detection how-to for full usage examples.
DetectorBuilder
The fluent builder is used to construct Detector instances with advanced settings not yet exposed in the primary Detector constructor, specifically max_concurrent_frames.
import locus
detector = (
locus.DetectorBuilder()
.with_family(locus.TagFamily.AprilTag36h11)
.with_threads(4)
.with_max_concurrent_frames(8) # Enable parallel batch processing
.build()
)
| Method | Description |
|---|---|
with_family(family) |
Add a tag family to detect. |
with_decimation(n) |
Spatial decimation factor (default 1). |
with_threads(n) |
Rayon intra-frame thread count (0 = all cores). |
with_corner_refinement(mode) |
CornerRefinementMode for subpixel accuracy. |
with_max_concurrent_frames(n) |
Pool size for detect_concurrent (default 1 = sequential). |
build() |
Build the Detector. |
detect_concurrent(frames, *, intrinsics=None, tag_size=None) -> list[DetectionResult]
Detect tags in multiple frames concurrently using Rayon. Releases the GIL for the entire parallel section. Pool contexts are managed internally. Rejected-corner data and telemetry are not available via this method.
| Parameter | Type | Description |
|---|---|---|
frames |
list[np.ndarray] |
List of (H, W) uint8 grayscale frames. |
intrinsics |
CameraIntrinsics \| None |
Camera intrinsics for 3D pose estimation. |
tag_size |
float \| None |
Physical tag side length in metres. |
Configuration
Locus uses Pydantic for robust configuration validation.
locus.DetectorConfig
Bases: BaseModel
Nested detector configuration — Python source of truth.
The three shipped profiles live in crates/locus-core/profiles/*.json
and are embedded into the Rust crate at compile time; the wheel reads
the exact same bytes through the FFI. Load via :meth:from_profile
for a shipped profile or :meth:from_profile_json for a user-supplied
JSON string.
Source code in crates/locus-py/locus/_config.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
Functions
from_profile
classmethod
from_profile(name: ProfileName) -> DetectorConfig
Load a shipped profile by name.
General-purpose profiles must stay on QuadExtractionPolicy::Static.
Adaptive routing lives in explicit opt-in profiles
(currently only max_recall_adaptive).
Source code in crates/locus-py/locus/_config.py
404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 | |
from_profile_json
classmethod
from_profile_json(json_str: str) -> DetectorConfig
Load a user-supplied profile from a JSON string.
Source code in crates/locus-py/locus/_config.py
424 425 426 427 | |
locus.DetectOptions
Bases: BaseModel
Per-call options for tag detection.
Source code in crates/locus-py/locus/_config.py
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
Data Models
These classes represent the output and internal state of the detection pipeline.
locus.DetectionBatch
dataclass
Vectorized detection results.
This dataclass contains parallel NumPy arrays representing a batch of detections.
Source code in crates/locus-py/locus/__init__.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
Attributes
centers
property
centers: ndarray
Compute centers from corners: (N, 2)
locus.Pose
Geometry
locus.CameraIntrinsics
Board Pose Estimation
Locus supports board-level 6-DOF pose estimation for AprilGrid and ChAruco boards.
All board types enforce dictionary bounds at construction time — a ValueError is raised
if the board requires more marker IDs than the target TagFamily provides.
For the underlying algorithm, see Board-Level Pose Estimation.
AprilGrid
locus.AprilGrid(
rows: int,
cols: int,
spacing: float, # gap between markers (metres)
marker_length: float, # physical marker side length (metres)
family: TagFamily,
)
Immutable topology for an AprilTag grid board. spacing = square_length - marker_length.
Raises ValueError if rows * cols > family.max_id_count().
| Attribute | Type | Description |
|---|---|---|
rows |
int |
Number of tag rows. |
cols |
int |
Number of tag columns. |
CharucoBoard
locus.CharucoBoard(
rows: int,
cols: int,
square_length: float, # physical checkerboard square side (metres)
marker_length: float, # physical ArUco marker side (metres)
family: TagFamily,
)
Immutable topology for a ChAruco board. Markers occupy squares where (row + col) is even.
Saddle points are at the outer corners of each square ((rows-1)*(cols-1) total).
Raises ValueError if the required marker count exceeds family.max_id_count().
| Attribute | Type | Description |
|---|---|---|
rows |
int |
Number of square rows. |
cols |
int |
Number of square columns. |
BoardEstimator
Unified stateful estimator for both AprilGrid and ChAruco boards. All scratch buffers
are pre-allocated at construction; estimate() performs zero heap allocations.
Construction:
# AprilGrid board
estimator = locus.BoardEstimator(board: AprilGrid)
# ChAruco board
estimator = locus.BoardEstimator.from_charuco(board: CharucoBoard)
Estimation:
result: BoardEstimateResult = estimator.estimate(
detector: locus.Detector,
img: np.ndarray, # (H, W) uint8 grayscale
intrinsics: CameraIntrinsics,
)
BoardEstimateResult attributes:
| Attribute | Shape / Type | Description |
|---|---|---|
ids |
(N,) int32 |
Decoded tag IDs visible in this frame. |
corners |
(N, 4, 2) float32 |
Refined tag corner image coordinates. |
board_pose |
(7,) float64 or None |
[tx, ty, tz, qx, qy, qz, qw] in camera frame — None if insufficient observations. Pose origin is the board's top-left marker corner. |
board_cov |
(6, 6) float64 or None |
Pose covariance in \(\mathfrak{se}(3)\) tangent space [t, ω]. |
Enumerations
locus.TagFamily
Bases: IntEnum
locus.CornerRefinementMode
Bases: IntEnum
locus.SegmentationConnectivity
Bases: IntEnum