tpt-cv
RustPure-Rust, zero-copy, modular computer vision framework — a permissively licensed (MIT/Apache-2.0), memory-safe alternative to OpenCV for WASM, edge/embedded, desktop, and GPU targets.
Languages
tpt-cv
A pure-Rust, modular, zero-copy computer vision framework.
tpt-cv is a ground-up, clean-room rewrite of core computer vision paradigms. It is a
modular, dependency-light alternative to OpenCV that runs on desktop, embedded/no_std
targets, WebAssembly, and GPUs (via wgpu).
Why
OpenCV is a 3-million-line C++ monolith: CMake hell, system dependency conflicts,
a sprawling API, and practically impossible to deploy to the web or bare-metal edge
devices. tpt-cv is memory-safe, permissively licensed, and universally deployable.
Core design principles
- 100% pure Rust & no_std capable — zero C/C++ FFI. Core math runs on bare-metal
microcontrollers (verified on
thumbv7em-none-eabihf) and in WebAssembly. - Zero-copy & data-oriented — images are contiguous, cache-friendly slices of memory; operations run in-place or via streaming iterators.
- Modular over monolithic — compile only what you need. Edge detection doesn't require the 3D or DNN modules.
- SIMD & GPU accelerated —
portable-simdon CPU with awgpuGPU compute path (verified on Intel UHD Graphics 770 at ~2.1× over SIMD on a 224² conv). - Strict MIT/Apache-2.0 — clean-room implementations of standard algorithms;
zero GPL/LGPL/AGPL code or dependencies. Enforced by
cargo-denyin CI.
Crates
| Crate | Description |
|---|---|
tpt-cv-core | Zero-copy image buffers, color spaces (RGB/BGR/Gray/HSV/YUV/YCbCr/Lab), pixel math (no_std, ARM/embedded verified) |
tpt-cv-filter | Separable convolutions, blurs, Sobel/Scharr, Canny, bilateral, median, Hough, adaptive threshold, morphology (no_std, SIMD) |
tpt-cv-feature | FAST corner detector, ORB descriptors, brute-force + LSH matching, single- and pyramidal Lucas-Kanade optical flow, pose-from-matches |
tpt-cv-geo | Homography/perspective warp, pinhole camera model, lens distortion, epipolar geometry, PnP solver |
tpt-cv-dnn | Clean-room ONNX inference runtime, CPU SIMD + wgpu GPU, INT8 quantization, control-flow (If/Loop/Scan) & recurrent (RNN/GRU/LSTM) ops, transformer attention primitives, numeric parity vs. reference |
Demos
document-scanner-wasm— web-native real-time document scanner (WASM). The full pipeline (grayscale → Gaussian blur → Canny → largest-quadrilateral → perspective warp) is verified by an offline synthetic-image test; the live-browser run is the remaining manual milestone.defect-inspector— high-throughput edge defect inspector over a simulated industrial image stream, with structured CSV/JSON logging and a sustained-throughput benchmark.frame-source— dependency-free,no_stddemo-layerFrameSourceabstraction shared by the demos above, unifying browser frame grabs and simulated camera streams behind one pluggable trait.tpt-cv-cli— command-line tool exposing the library (blur/edges/morph/features/warp/infer) over PNG/JPEG files, sotpt-cvis usable without writing Rust.
How it compares to image / imageproc
For pure-Rust image handling, most Rust developers reach for the image +
imageproc pair first. They are excellent — and complementary to tpt-cv:
tpt-cv | image + imageproc | |
|---|---|---|
| Focus | Real-time CV pipeline: filters, features, geometry, ONNX inference | General image I/O, codecs, and classic image-processing algorithms |
| Buffer model | Zero-copy Image<T, C> views over &[T] with stride/sub-image support; caller-provided destination buffers | Owned ImageBuffer<P, Vec<S>>; many ops allocate their output |
| Generics | Generic over sample type (u8/u16/f32) and channel count via const generics | Generic over pixel type P: Pixel |
| no_std / embedded | Yes (thumbv7em-none-eabihf verified) | No (std required) |
| SIMD / GPU | portable-simd scalar-fallback path + optional wgpu compute backend | Scalar only |
| Camera geometry | Homography/epipolar/PnP/calibration/lens distortion | None |
| DNN inference | Clean-room ONNX runtime (CPU SIMD + GPU) | None |
| Licensing | MIT OR Apache-2.0, zero-GPL dependency policy enforced by cargo-deny | MIT |
| Codecs (PNG/JPEG/…) | Not provided by design — pair with image (see demos) | Yes |
Rule of thumb: use image for decoding files into buffers, then hand the raw
samples to tpt-cv for analysis. The demos do exactly that.
Quick start
cargo build --release
cargo test --workspace
WASM demo (requires wasm-pack and
trunk):
cd demos/document-scanner-wasm
trunk serve
Using a crate
[dependencies]
tpt-cv-filter = "0.1"
tpt-cv-core = { version = "0.1", default-features = false } # for no_std
use tpt_cv_core::Image;
use tpt_cv_filter::canny;
// ...see the per-crate docs for full APIs.
Cross-compilation & compliance checks
These are wired into CI and run from a clean checkout:
cargo build --target wasm32-unknown-unknown --workspace
cargo build -p tpt-cv-core --no-default-features --target thumbv7em-none-eabihf
cargo fmt --all --check
cargo clippy --workspace --all-targets -- -D warnings
cargo deny check
Status
All five core crates and four demos are implemented and pass cargo test /
cargo clippy / cargo doc on the workspace. Highlights:
tpt-cv-dnnloads real exported ONNX models (opset 13) and matches an independentonnxruntimereference to <1e-3; thewgpuGPU path matches the CPU path to ~1e-6. Operator coverage now includes elementwise ops (with a shared unary-activation kernel:Tanh,Elu,Selu,Gelu, ...), normalization (LayerNormalization,InstanceNormalization,GroupNormalization,LRN),ConvTransposeandMatMulInteger, reductions, shape/tensor ops (Tile,Expand,ConstantOfShape,Range,ScatterElements), INT8 quantization (QLinearConvwith groups + per-axis scales + quantize/dequantize), control flow (If/Loop/Scanvia nested sub-graph compilation), and the recurrent family (RNN,GRU,LSTMwith optional peepholes, bidirectional traversal). Anattentionmodule provides scaled dot-product and multi-head attention as a CPU reference for ViT/DETR-class graphs. Seedocs/onnx-opset-gaps.mdfor the supported operator subset and known gaps; seedocs/model-zoo.mdfor known-working fixtures.tpt-cv-featureadds single- and pyramidal (coarse-to-fine) sparse Lucas-Kanade optical flow and arecover_pose_from_matcheswrapper;tpt-cv-geoadds a PnP solver.tpt-cv-filteradds bilateral/median filters, Hough line/circle detection, and adaptive thresholding.tpt-cv-coreadds YCbCr and CIE L*a*b* color conversions.filter::pipelineprovides a declarative zero-copy pipeline abstraction with allocation-free ping-pong buffer reuse across repeated frames.no_stdis verified on an ARM Cortex-M target fortpt-cv-coreandtpt-cv-filter.- Fuzzing covers the ONNX parser and session runner (
fuzz/) so malformed models never panic or UB. Security hardening (overflow checks, shape caps, validated casts) is documented indocs/security-audit-2026-08.md.
Remaining work is external/publishing: crates.io release, v1.0.0 tag, and Pages
deploys for the demos. See todo.md and CHANGELOG.md.
Documentation & migration
-
ARCHITECTURE.md— internal design and DNN pipeline. -
docs/migrating-from-opencv.md—cv::→tpt-cvfunction mappings. -
docs/starter-template.md— bootstrap a minimal new project on top oftpt-cv. -
docs/model-zoo.md— known-working ONNX fixtures, including INT8 quantization. -
docs/adr/0001-spec-clarifications.md— the fourspec.txtclarifications (nospark, clean-room ONNX, peripheral deps in demos only, simulated camera feed for MVP2).
License
Dual-licensed under MIT OR Apache-2.0. Copyright (c) 2026 TPT Solutions.
See LICENSE-MIT and LICENSE-APACHE.