Skip to main content

TemplateMatcher

Struct TemplateMatcher 

Source
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

Source

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.

Source

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.

Trait Implementations§

Source§

impl Detector for TemplateMatcher

Source§

fn evaluate( &mut self, view: &FrameView<'_>, ) -> Result<DetectorOutput, DetectorError>

Source§

fn is_heavy(&self) -> bool

Heavy detectors (OCR, ML inference) are routed to the blocking thread pool by the watcher loop so they never stall the async scheduler. Cheap pixel-math detectors keep the default false.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more