add homography transformer

This commit is contained in:
Marc Planard 2023-07-01 16:01:11 +02:00
parent ddf44460ae
commit ee9e3f1da0
3 changed files with 43 additions and 3 deletions

View File

@ -46,8 +46,9 @@ pub enum TransformConf {
#[serde(rename = "flip_vertical")]
FlipV(transformer::FlipVertical),
#[serde(rename = "grid")]
Grid(transformer::Grid)
Grid(transformer::Grid),
#[serde(rename = "homography")]
Homography(transformer::Homography)
}
@ -70,7 +71,8 @@ impl Conf {
TransformConf::Rotate(r) => Box::new(*r),
TransformConf::FlipH(r) => Box::new(*r),
TransformConf::FlipV(r) => Box::new(*r),
TransformConf::Grid(r) => Box::new(*r)
TransformConf::Grid(r) => Box::new(*r),
TransformConf::Homography(r) => Box::new(*r),
};
v.push(t);
}

View File

@ -5,6 +5,7 @@ mod rotate;
mod flip_horizontal;
mod flip_vertical;
mod grid;
mod homography;
use crate::point::Point;
use crate::worldstate::WorldState;
@ -16,6 +17,7 @@ pub use rotate::Rotate;
pub use flip_horizontal::FlipHorizontal;
pub use flip_vertical::FlipVertical;
pub use grid::Grid;
pub use self::homography::Homography;
pub trait Transformers {
fn apply(

View File

@ -0,0 +1,36 @@
use crate::transformer::Transformers;
use crate::point::Point;
use crate::worldstate::WorldState;
use serde::{Serialize,Deserialize};
use log::info;
use nalgebra::Matrix3;
/// Homography
#[derive(Serialize,Deserialize,Debug,Clone,Copy)]
pub struct Homography {}
impl Transformers for Homography {
fn apply(&self, point_list: &[Point], ws: &WorldState) -> Vec<Point> {
let m = ws.edh.matrix;
point_list.iter()
.map(| point | {
// THIS IS CERTAINLY ALL WRONG! NEEDS DEBUGING!!!
let p = Matrix3::new(point.x, point.y, 1.0,
1.0, 1.0, 1.0,
1.0, 1.0, 1.0);
let dot = p.tr_dot(&m);
let new_p = Point { x: point.x / dot, y: point.y / dot,
..*point
};
info!("{:?} => {:?}", point, new_p);
new_p
})
.collect()
}
}