use crate::structs_f64::query::{Query, QueryPoint};
use image::GrayImage;
use std::ops::Deref;
pub const PATCH_SIZE: u32 = 20;
pub struct QueryPointCandidate {
pub x: f64,
pub y: f64,
}
pub trait PointDetector {
fn extract_from_img(&self, img: &GrayImage) -> Vec<QueryPointCandidate>;
}
pub trait PointFitter {
fn fit_point(&self, point: &QueryPointCandidate, img: &GrayImage) -> QueryPoint;
}
pub fn create_query(
filename: &str,
img: &GrayImage,
point_detector_box: Box<dyn PointDetector>,
point_fitter_box: Box<dyn PointFitter>,
) -> Query {
let point_detector: &dyn PointDetector = point_detector_box.deref();
let point_fitter: &dyn PointFitter = point_fitter_box.deref();
let point_candidates: Vec<QueryPointCandidate> =
PointDetector::extract_from_img(point_detector, img);
let points = point_candidates
.iter()
.map(|candidate| PointFitter::fit_point(point_fitter, candidate, img))
.collect();
Query::new(filename, img.dimensions().0, img.dimensions().1, points)
}