โ† All models

optical-flow ยท vision ยท WASM ยท ~64 MB

RAFT โ€” dense optical flow between two frames

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.

At a glance

Modelopencv/optical_flow_estimation_raft โ€” RAFT (Teed & Deng, ECCV 2020), Sintel-trained
Taskoptical-flow (dense two-frame motion estimation) โ€” run via raw ONNX Runtime Web (see note below)
Runtimeonnxruntime-web 1.21 (transformers.js has no optical-flow class / no optical-flow task)
Inputtwo frames [1, 3, 360, 480] float32 in 0โ€“255 (plain RGB, fixed size) โ€” frame 1 and frame 2
Outputflow field [1, 2, 360, 480] float32 โ€” channel 0 = horizontal motion u, channel 1 = vertical motion v, in pixels
Quantizationfp32 ONNX โ€” runs on the plain WASM execution provider, no WebGPU needed (the int8 export aborts on WASM)
BackendWebAssembly (single-threaded on GitHub Pages) โ€” a 360ร—480 pass runs in ~6 s
Download~64 MB, cached after first load (auto-inits on return)
LicenseBSD-3-Clause (RAFT, princeton-vl) ยท MIT (ONNX conversion by PINTO0309, via OpenCV Zoo)
Web APIsWebAssembly, Web Workers, OffscreenCanvas, ImageBitmap โ€” all Baseline widely available

Run it

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.

direction โ†’ colour

Frame 1
Frame 2 (moved)
RAFT flow (colour = direction, brightness = speed)

Why raw ONNX Runtime Web?

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.