use crate::frame::Frame;
use crate::matcher::{Match, Matcher};
use crate::template::Template;
use corrmatch::{
CompileConfig, ImageView, MatchConfig, RotationMode, Template as CorrTemplate,
Matcher as CorrInner,
};
pub struct CorrMatcher;
impl CorrMatcher {
pub fn new() -> Self {
CorrMatcher
}
}
impl Default for CorrMatcher {
fn default() -> Self {
Self::new()
}
}
impl Matcher for CorrMatcher {
fn find(&self, frame: &Frame, tpl: &Template) -> Option<Match> {
let corr_tpl = CorrTemplate::new(tpl.to_gray(), tpl.width, tpl.height).ok()?;
let compiled = corr_tpl.compile(CompileConfig::default()).ok()?;
let inner = CorrInner::new(compiled).with_config(MatchConfig {
rotation: RotationMode::Disabled,
..MatchConfig::default()
});
let gray = frame.to_gray();
let view = ImageView::from_slice(&gray, frame.width, frame.height).ok()?;
let res = inner.match_image(view).ok()?;
Some(Match { x: res.x as i32, y: res.y as i32, score: res.score })
}
}