WebARKitLib-rs π¦
WebARKitLib-rs is a high-performance, memory-safe Rust port of the WebARKitLib (originally C/C++).
This project aims to provide a pure-Rust implementation of the core ARToolKit algorithms, targeting both native systems and WebAssembly (WASM) for high-performance augmented reality in the browser.
[!NOTE] This project is currently a Work in Progress. While the core marker detection and pose estimation are functional, we are continuously optimizing and expanding the feature set.
π Key Features
- Pure Rust: Built for safety, speed, and modern concurrency. (crates.io)
- Dual WASM Strategy: Automated release of both Standard and SIMD binaries to maximize performance and compatibility.
- SIMD-Accelerated Pattern Matching: Uses
i16fixed-point arithmetic and WASMi32x4_dot_i16x8instructions for ultra-fast correlation matching. - Barcode Marker Support: Robust decoding for square matrix markers (3x3 to 6x6) with ECC.
- WASM Ready: High-performance tracking in the browser via WebAssembly. (@webarkit/webarkitlib-wasm)
- Side-Effect Free: Pure mathematical engine, easy to test and integrate.
- CI-Integrated Benchmarking: Performance parity with original C implementation.
β‘ Performance & Accuracy
- SIMD-Accelerated Pattern Matching: Uses
i16fixed-point arithmetic for the core correlation loops, leveraging WASMi32x4_dot_i16x8instructions for significant speedups. - Numerical Parity: Our SIMD and Scalar paths are calibrated to produce bit-identical results (including rounding logic in grayscale and thresholding), ensuring deterministic behavior across all devices.
- Sub-millisecond Tracking: Core detection loop is optimized for sub-millisecond execution on standard ARM/x86 hardware.
π Getting Started
Native Rust Example
To see the marker detection in action on your local machine, run the provided simple example:
This example loads a camera parameter file, a marker (pattern or barcode), and a sample image, performing detection and outputting the 3D pose extrinsics.
Barcode Detection Example
A unified, parameterized barcode example is available for testing all supported matrix code types:
# Default: 3x3 matrix code type, auto-sweeps threshold 60β180
# Specify a matrix code type (e.g. 4x4) and supply the matching marker image
# Use a fixed threshold instead of auto-sweeping
# Full example: type, threshold, and custom image path
Options:
| Flag | Long form | Description | Default |
|---|---|---|---|
-m |
--matrix-code-type |
Matrix code type (3x3, 3x3parity65, 3x3hamming63, 4x4, 4x4bch1393, 4x4bch1355, 5x5, 5x5bch22125, 5x5bch2277, 6x6) |
3x3 |
-t |
--threshold |
Fixed labeling threshold (0β255). When omitted, sweeps 60β180 in steps of 20 | (auto-sweep) |
-i |
--image |
Path to the input image | bundled 3x3 marker image |
WebAssembly (WASM) Demo
The WASM port allows you to run the AR engine directly in most modern browsers.
-
Build the modules: Use the npm script to generate both Standard and SIMD bundles (works on all platforms):
Alternatively, download the pre-built
wasm-packageartifact from the latest CI run and extract its contents intocrates/wasm/pkg/. -
Run the demo: The
wwwfolder contains two web demos. Serve it with any local HTTP server:# Serve using any local HTTP server, e.g.:simple.htmlβ static image demo with engine selector and threshold visualization.simple_video_marker_example.htmlβ live webcam demo with engine selector, marker type (pattern/barcode) selector, and threshold slider.
π Benchmarking
We maintain a strict performance comparison with the original C library to ensure our Rust port remains competitive.
Detailed SIMD performance results and reproduction steps can be found in the BENCHMARKS.md file.
Running the Comparison
-
Bootstrap the C library:
-
Execute the Suite:
# Rust Benchmark # C Benchmark (Manual build required once)
Tracking Performance
We use criterion to track performance over time. You can save specific snapshots as "baselines":
# Save a milestone baseline
ποΈ Project Structure
crates/core: The core AR engine (pure Rust).crates/wasm: WASM bindings, dual-build scripts, and diagnostic web demo.benchmarks: C vs Rust performance comparison suite.examples: Usage demonstrations for patterns and barcodes.ARCHITECTURE.md: Detailed technical overview of the library's design and SIMD optimizations.
πΊοΈ Roadmap
π― Near-term Goals (v1.0.0+)
- Enhanced Documentation: Expand API reference, integration walkthroughs for JS/TS, and provide detailed usage examples.
- WASM Memory Management: Improve resource cleanup when switching engines or markers in long-running browser sessions.
π Long-term Vision
- Multi-Marker Support: Port
arMultilogic to enable tracking of multiple markers simultaneously. - KPM/NFT (Natural Feature Tracking): Implement robust tracking of arbitrary images and surfaces.
- Advanced Video Abstraction: Develop a cross-platform video handling layer to simplify integration with various input sources.
π Credits
This project is a port of the excellent WebARKitLib project. Special thanks to the original ARToolKit contributors.
π License
This project is licensed under the LGPLv3 License - see the LICENSE file for details.