aruco_rs/lib.rs
1// Copyright (c) 2026 kalwalt and AR.js-org contributors
2//
3// This software is released under the MIT License.
4// https://opensource.org/licenses/MIT
5// See https://github.com/AR-js-org/aruco-rs/blob/main/LICENSE
6use nalgebra::Vector2;
7
8/// 2D Point with floating point precision (f32 for SIMD/WASM compatibility)
9pub type Point2f = Vector2<f32>;
10
11/// 2D Point in pixel coordinates
12pub type Point2i = Vector2<i32>;
13
14/// The four corners of a detected marker
15pub type MarkerCorners = [Point2f; 4];
16
17/// Core structure for a detected ArUco marker.
18///
19/// # Fields
20/// * `id` - The numeric dictionary ID of the identified marker.
21/// * `corners` - The 4 corners bounding the marker in 2D image coordinates.
22/// * `hamming_distance` - The Hamming distance calculated during error correction.
23#[derive(Debug, Clone)]
24pub struct Marker {
25 pub id: i32,
26 pub corners: MarkerCorners,
27 pub hamming_distance: i32,
28}
29
30/// Zero-copy image buffer for JS/Native interop.
31/// Designed to map WASM memory or native video buffers without copying.
32///
33/// # Fields
34/// * `data` - A slice representing a 1D contiguous array of 8-bit pixels.
35/// * `width` - The logical width of the frame in pixels.
36/// * `height` - The logical height of the frame in pixels.
37pub struct ImageBuffer<'a> {
38 pub data: &'a [u8],
39 pub width: u32,
40 pub height: u32,
41}
42
43/// Possible errors during detection or calibration
44#[derive(Debug)]
45pub enum ArUcoError {
46 InvalidBuffer,
47 MarkerNotFound,
48 PoseEstimationFailed,
49 DictionaryMismatch,
50}
51
52pub type Result<T> = std::result::Result<T, ArUcoError>;
53
54pub mod core;
55pub mod cv;
56pub mod pose;
57pub mod simd;
58
59#[cfg(feature = "wasm")]
60pub mod wasm_bridge;