Skip to content

About

GPU-accelerated template matching for Remaku, imported from urholaukkarinen/template-matching under the MIT license.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

template-matching

This GPU-accelerated template matching library for Rust is based on template-matching, originally created by Urho Laukkarinen. The Remaku project maintains this version. See LICENSE for the original MIT license and copyright notice.

Installation

[dependencies]
template-matching = { git = "https://github.com/remaku/template-matching", features = ["image"] }

For reproducible application builds, also specify a full commit hash with rev.

Fallible API

Remaku uses TemplateMatcher::try_new, try_match_template, and poll_result. poll_result returns Ok(None) while a submitted job is pending (or when idle), Ok(Some(image)) when ready, and Err on a device or readback failure. Polling does not wait for GPU completion. A pending job must be collected before another submission. try_wait_for_result provides a fallible blocking convenience method. The original convenience methods still panic on failures.

Disable default features and use Image::new with borrowed f32 slices to avoid depending on this crate's optional image 0.24 integration.

Usage

use template_matching::{find_extremes, match_template, MatchTemplateMethod, TemplateMatcher};

fn main() {
    // Load images and convert them to f32 grayscale
    let input_image = image::load_from_memory(include_bytes!("input.png")).unwrap().to_luma32f();
    let template_image = image::load_from_memory(include_bytes!("template.png")).unwrap().to_luma32f();

    let result = match_template(&input_image, &template_image, MatchTemplateMethod::SumOfSquaredDifferences);

    // Or alternatively you can create the matcher first
    let mut matcher = TemplateMatcher::new();
    matcher.match_template(&input_image, &template_image, MatchTemplateMethod::SumOfSquaredDifferences);
    let result = matcher.wait_for_result().unwrap();

    // Calculate min & max values
    let extremes = find_extremes(&result);
}

About

GPU-accelerated template matching for Remaku, imported from urholaukkarinen/template-matching under the MIT license.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages