#optical-flow #computer-vision #tracking #visual-odometry #feature-detection

optical-flow-lk

Rust implementation of Lucas-Kanade optical flow and Shi-Tomasi feature detection

1 unstable release

new 0.1.0 Feb 16, 2025

#948 in Algorithms

Download history 81/week @ 2025-02-11

81 downloads per month

MIT license

710KB
393 lines

Lucas Canade Optical Flow and Shi-Tomasi feature detection on Rust

Crates.io Documentation

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 image and imageproc crates
  • 🌐 WebAssembly (Wasm) compatible

Usage

Add to your Cargo.toml:

[dependencies]
optical-flow-lk = "0.1"

Basic example:

use image::{open, GrayImage, Rgba};
use optical_flow_lk::{build_pyramid, calc_optical_flow, good_features_to_track};

let prev_frame: GrayImage = open("examples/input1.png").unwrap().clone().into_luma8();
let next_frame: GrayImage = open("examples/input2.png").unwrap().clone().into_luma8();

let prev_frame_pyr = build_pyramid(&prev_frame, 4);
let next_frame_pyr = build_pyramid(&next_frame, 4);

let mut points = good_features_to_track(&prev_frame, 0.1, 5);
points.truncate(100);
let prev_points: Vec<(f32, f32)> = points.iter().map(|&x| (x.0 as f32, x.1 as f32)).collect();

let next_points = calc_optical_flow(&prev_frame_pyr, &next_frame_pyr, &prev_points, 21, 30);

Dependencies

~10MB
~207K SLoC