This crate provides basic functionality to find likely positions of a subimage within a larger image by calculating an image distance. It has a naive scalar implementation in rust, and a simd implementation that selects the best implementation based on cpu features at runtime in rust using the simdeez crate. It also provides an implementation which uses OpenCV's (A C++ library) matchTemplate function using the opencv-rust crate through an optional off-by-default feature. It can also optionally convert images to grayscale before applying the algorithms.
Here's a simple example showing how to use the API:
# // If you modify this example, please also update it's copy in README.md
use ;
// Make a dummy 128x128 black image with a red dot at (50, 0)
let = ;
let mut rgb_image = vec!;
rgb_image = 250;
// Make a dummy 32x32 black image
// with a red dot at (0, 0)
let = ;
let mut rgb_subimage = vec!;
rgb_subimage = 250;
let mut finder = new;
// These are (x, y, distance) where x and y are the position within the larger image
// and distance is the distance value, where a smaller distance means a more precise match
let positions: & =
finder.find_subimage_positions;
let max: = positions
.iter
.min_by;
println!;
assert_eq!;
// find_subimage_positions actually returns the results sorted by distance already,
// so we can skip finding the minimum
assert_eq!;
The most important functions provided are find_subimage_positions and find_subimage_positions_as_grayscale.
You may find their "_with_backend" versions useful.
By default, this library prunes results that are close together. You can disable (Set to 0) or tweak this using with_pruning.
You can look at the page for the [Backend] enum to learn about the possible backends.
There are some examples in the /examples folder in the repository.