tpt-cv

Rust

Pure-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.

1 stars0 forks1 watchersApache License 2.0
computer-visioncvedge-computingembeddedfeature-detectionimage-filtersimage-processingmachine-learningmodularneural-networkno-stdonnxrustsimdwasmzero-copy

Languages

Rust98.5%Python1.5%
README

tpt-cv

CI License: MIT OR Apache-2.0 docs.rs MSRV: 1.85.0

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 acceleratedportable-simd on CPU with a wgpu GPU 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-deny in CI.

Crates

CrateDescription
tpt-cv-coreZero-copy image buffers, color spaces (RGB/BGR/Gray/HSV/YUV/YCbCr/Lab), pixel math (no_std, ARM/embedded verified)
tpt-cv-filterSeparable convolutions, blurs, Sobel/Scharr, Canny, bilateral, median, Hough, adaptive threshold, morphology (no_std, SIMD)
tpt-cv-featureFAST corner detector, ORB descriptors, brute-force + LSH matching, single- and pyramidal Lucas-Kanade optical flow, pose-from-matches
tpt-cv-geoHomography/perspective warp, pinhole camera model, lens distortion, epipolar geometry, PnP solver
tpt-cv-dnnClean-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_std demo-layer FrameSource abstraction 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, so tpt-cv is 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-cvimage + imageproc
FocusReal-time CV pipeline: filters, features, geometry, ONNX inferenceGeneral image I/O, codecs, and classic image-processing algorithms
Buffer modelZero-copy Image<T, C> views over &[T] with stride/sub-image support; caller-provided destination buffersOwned ImageBuffer<P, Vec<S>>; many ops allocate their output
GenericsGeneric over sample type (u8/u16/f32) and channel count via const genericsGeneric over pixel type P: Pixel
no_std / embeddedYes (thumbv7em-none-eabihf verified)No (std required)
SIMD / GPUportable-simd scalar-fallback path + optional wgpu compute backendScalar only
Camera geometryHomography/epipolar/PnP/calibration/lens distortionNone
DNN inferenceClean-room ONNX runtime (CPU SIMD + GPU)None
LicensingMIT OR Apache-2.0, zero-GPL dependency policy enforced by cargo-denyMIT
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-dnn loads real exported ONNX models (opset 13) and matches an independent onnxruntime reference to <1e-3; the wgpu GPU 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), ConvTranspose and MatMulInteger, reductions, shape/tensor ops (Tile, Expand, ConstantOfShape, Range, ScatterElements), INT8 quantization (QLinearConv with groups + per-axis scales + quantize/dequantize), control flow (If/Loop/Scan via nested sub-graph compilation), and the recurrent family (RNN, GRU, LSTM with optional peepholes, bidirectional traversal). An attention module provides scaled dot-product and multi-head attention as a CPU reference for ViT/DETR-class graphs. See docs/onnx-opset-gaps.md for the supported operator subset and known gaps; see docs/model-zoo.md for known-working fixtures.
  • tpt-cv-feature adds single- and pyramidal (coarse-to-fine) sparse Lucas-Kanade optical flow and a recover_pose_from_matches wrapper; tpt-cv-geo adds a PnP solver.
  • tpt-cv-filter adds bilateral/median filters, Hough line/circle detection, and adaptive thresholding. tpt-cv-core adds YCbCr and CIE L*a*b* color conversions.
  • filter::pipeline provides a declarative zero-copy pipeline abstraction with allocation-free ping-pong buffer reuse across repeated frames.
  • no_std is verified on an ARM Cortex-M target for tpt-cv-core and tpt-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 in docs/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

License

Dual-licensed under MIT OR Apache-2.0. Copyright (c) 2026 TPT Solutions. See LICENSE-MIT and LICENSE-APACHE.