pub struct TemplateMatcher { /* private fields */ }Expand description
Grayscale normalized cross-correlation template matcher.
evaluate slides the template over the region and returns the best match
as DetectorOutput::Score in 0.0..=1.0 (negative correlation clamps to
0). Naive O(region * template) search — fine for the small regions and
icons this library targets; optimize (integral images / FFT) only if
profiling ever demands it.
Degenerate (flat) inputs fall back to mean comparison: a flat template scores 1.0 on a window of the same mean brightness, else 0.0.
NCC is contrast-invariant: a dim copy of the pattern scores as high as a bright one, so the score says nothing about absolute brightness/contrast. A template larger than the watched region scores 0.0 (“not found”) rather than erroring — check your region size if a template watcher never fires.
Implementations§
Source§impl TemplateMatcher
impl TemplateMatcher
Sourcepub fn from_luma(
width: u32,
height: u32,
luma: Vec<u8>,
) -> Result<TemplateMatcher, DetectorError>
pub fn from_luma( width: u32, height: u32, luma: Vec<u8>, ) -> Result<TemplateMatcher, DetectorError>
Build from a row-major grayscale buffer. Errors if luma.len() does
not equal width * height or either dimension is zero.
Sourcepub fn from_png_bytes(bytes: &[u8]) -> Result<TemplateMatcher, DetectorError>
pub fn from_png_bytes(bytes: &[u8]) -> Result<TemplateMatcher, DetectorError>
Build from encoded image bytes (PNG). Color images are converted to grayscale; matching is luma-only. Alpha is ignored (not composited); export icons with an opaque background.