add homography transformer
This commit is contained in:
parent
ddf44460ae
commit
ee9e3f1da0
@ -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);
|
||||
}
|
||||
|
@ -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(
|
||||
|
36
src/transformer/homography.rs
Normal file
36
src/transformer/homography.rs
Normal 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()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user