add homography transformer
This commit is contained in:
parent
ddf44460ae
commit
ee9e3f1da0
3 changed files with 43 additions and 3 deletions
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…
Add table
Add a link
Reference in a new issue