#opencv #image-stacking


Image alignment and stacking functions based on OpenCV and Rayon

6 releases

0.0.6 Nov 21, 2021
0.0.5 Nov 5, 2021
0.0.3 Oct 31, 2021

#7 in #opencv

Download history 1/week @ 2022-01-31 6/week @ 2022-02-21 19/week @ 2022-03-14 18/week @ 2022-03-21 6/week @ 2022-04-04 37/week @ 2022-04-25 36/week @ 2022-05-02 6/week @ 2022-05-09

79 downloads per month


366 lines

crates.io Documentation Workflow dependency status license


A multi-threaded port of the python code found here: github.com/maitek/image_stacking

This crate contains multi-threaded functions that aligns and stacks images using OpenCV and Rayon.

Read more about image alignment with OpenCV here.


Download the test images:

git clone https://github.com/maitek/image_stacking image_stacking_py

Build the code:

Opencv-rust can be little tricky to install. Follow the instructions from rust opencv

cargo build --release

Run the example:

cargo run --example main --release

and then wait a few seconds. The program should sort the images by quality, drop the least sharp image, and align and stack the rest. The result should be two windows showing the stacked images using two different alignment methods.


let keypoint_match_img:opencv::core::Mat = keypoint_match(
   // a Vec<PathBuf> containing paths to image files
   KeyPointMatchParameters {
      method: opencv::calib3d::RANSAC,
      ransac_reproj_threshold: 5.0,

Depending on the parameters the ecc_match() is much slower, but also more accurate.

let ecc_match_img:opencv::core::Mat = ecc_match(
   // a Vec<PathBuf> containing paths to image files
   EccMatchParameters {
      motion_type: MotionType::Homography,
      max_count: Some(5000),
      epsilon: Some(1e-5),
      gauss_filt_size: 5,


  • Figure out the docs.rs problem
  • Figure out what to do with .reshape() in keypoint_match()
  • Figure out some opencv parameters responsibility sneakily shifted to end user.
  • Complete the sharpness_tenengrad() function. Mat not square?
  • Command line options in the example


Licensed under either of

at your option.


~171K SLoC