optical-flow ยท vision ยท WASM ยท ~64 MB
Optical flow answers a deceptively hard question: where did every pixel go between two frames? RAFT (Recurrent All-Pairs Field Transforms) builds a 4D volume of all-pairs pixel correlations and iteratively refines a dense per-pixel motion field โ a vector for every pixel giving the direction and speed it moved. It's the engine under video stabilisation, frame interpolation, motion segmentation, and tracking. Here it runs entirely on your device via ONNX Runtime Web: move a photo by a known amount and watch RAFT recover it, pixel by pixel. Nothing leaves the tab.
| Model | opencv/optical_flow_estimation_raft โ RAFT (Teed & Deng, ECCV 2020), Sintel-trained |
|---|---|
| Task | optical-flow (dense two-frame motion estimation) โ run via raw ONNX Runtime Web (see note below) |
| Runtime | onnxruntime-web 1.21 (transformers.js has no optical-flow class / no optical-flow task) |
| Input | two frames [1, 3, 360, 480] float32 in 0โ255 (plain RGB, fixed size) โ frame 1 and frame 2 |
| Output | flow field [1, 2, 360, 480] float32 โ channel 0 = horizontal motion u, channel 1 = vertical motion v, in pixels |
| Quantization | fp32 ONNX โ runs on the plain WASM execution provider, no WebGPU needed (the int8 export aborts on WASM) |
| Backend | WebAssembly (single-threaded on GitHub Pages) โ a 360ร480 pass runs in ~6 s |
| Download | ~64 MB, cached after first load (auto-inits on return) |
| License | BSD-3-Clause (RAFT, princeton-vl) ยท MIT (ONNX conversion by PINTO0309, via OpenCV Zoo) |
| Web APIs | WebAssembly, Web Workers, OffscreenCanvas, ImageBitmap โ all Baseline widely available |
Pick a photo and a motion. We build frame 2 by shifting the scene by a known number of pixels, so you can check RAFT's answer against the truth. Colour shows direction (see the wheel); brightness of colour shows speed. Grey = no motion.
Transformers.js registers no optical-flow model class and has no optical-flow pipeline
task, so we run RAFT's ONNX graph directly with onnxruntime-web and hand-write the pre/post a
pipeline would own: resize both frames to the model's fixed 360ร480, pack them as
[1,3,360,480] float32 in 0โ255, and colour-code the returned [1,2,360,480]
motion field. Everything โ download, inference, rendering โ happens on your device.