Lucas Canade Optical Flow and Shi-Tomasi feature detection on Rust
High-performance Rust implementation of Lucas-Kanade optical flow and Shi-Tomasi feature detection, optimized for real-time applications and WebAssembly (Wasm) compatibility.
Features
- 🔍 Efficient feature point detection using Shi-Tomasi
- 🖼️ Integration with
imageandimageproccrates - 🌐 WebAssembly (Wasm) compatible
Usage
Add to your Cargo.toml:
[]
= "0.1"
Basic example:
use ;
use ;
let prev_frame: GrayImage = open.unwrap.clone.into_luma8;
let next_frame: GrayImage = open.unwrap.clone.into_luma8;
let prev_frame_pyr = build_pyramid;
let next_frame_pyr = build_pyramid;
let mut points = good_features_to_track;
points.truncate;
let prev_points: = points.iter.map.collect;
let next_points = calc_optical_flow;
Live demo
A browser demo runs the tracker entirely client-side in WebAssembly: point your phone's camera at a scene and tap to drop points (or hit Auto to detect Shi-Tomasi corners) and watch them ride the optical flow.
Source and build instructions are in web-demo/.
WebAssembly
The Scharr gradient kernel has a hand-written simd128 path that is selected
automatically on wasm32 — but only when the target is built with SIMD
enabled, since WASM has no runtime feature detection. The bundled
.cargo/config.toml sets this for you:
[]
= ["-C", "target-feature=+simd128"]
If you build from a different working directory (so that config is not picked up), pass it yourself:
RUSTFLAGS="-C target-feature=+simd128"
Without +simd128 the crate still works, falling back to a scalar gradient
loop. For production WASM, also run wasm-opt -O3 on the output. On a 640×480
per-frame track step, the simd128 build plus the bounds-check-free bilinear
sampler is roughly 2× faster than the scalar build in V8 (Node).