corner-pin homography

This commit is contained in:
Ruben van de Ven 2025-07-04 13:27:09 +02:00
parent 3a87be73f9
commit 8cc79b24a7

View file

@ -1077,24 +1077,24 @@ fn map_mouse_moved(_app: &App, model: &mut GuiModel, pos: Point2) {
let config = model.per_laser_config.get_mut(&dac_id).expect("Dac config unavailable");
// 1. reverse the canvas space to world space:
// 1. For the dragging point, reverse the canvas space to world space:
let world_point = [
(pos[0] - model.canvas_translate.x) / model.canvas_scale,
(pos[1] - model.canvas_translate.y) / -model.canvas_scale,
];
// 1.b reverse the filters _except homography_ on the world point, to get the source_point
// TODO
// 2. find existing corners in world space, replacing the
// dragging corner
let mut world_corners = laser_corners_to_world(&config.filters);
world_corners[corner.index()] = world_point;
// 3. find new homography:
// let matches = Vec::new();
// 3. find the corners of the laser, correct them for all
// geometric filters, except the homography itself.
let laser_corners: LaserPoints = Corner::in_laser_space().into();
let distorted_laser_corners: Vec<[f32;2]> = config.filters.reverse_without_homography(&laser_corners).into();
// 4. find new homography:
let matches: Vec<FeatureMatch<nalgebra::Point2<f64>>> = world_corners.iter().zip(distorted_laser_corners).map(|(world, laser)| {
FeatureMatch(
nalgebra::Point2::new(world[0] as f64, world[1] as f64),
@ -1102,40 +1102,13 @@ fn map_mouse_moved(_app: &App, model: &mut GuiModel, pos: Point2) {
)
}).collect::<Vec<_>>();
dbg!(&matches);
// 4. apply
// let matches = vec![
// FeatureMatch(nalgebra::Point2::new(0.0 as f64, 0.0 as f64), nalgebra::Point2::new(0.0 as f64, 2.0 as f64)),
// FeatureMatch(nalgebra::Point2::new(1.0 as f64, 1.0 as f64), nalgebra::Point2::new(1.0 as f64, 3.0 as f64)),
// FeatureMatch(nalgebra::Point2::new(2.0 as f64, 4.0 as f64), nalgebra::Point2::new(2.0 as f64, 6.0 as f64)),
// FeatureMatch(nalgebra::Point2::new(7.0 as f64, 3.0 as f64), nalgebra::Point2::new(7.0 as f64, 5.0 as f64)),
// ];
// nalgebra::base::Matrix3, which should become glam::f32::Mat3
let m = find_homography(matches).unwrap();
let mat: Mat3 = Mat3::from_cols_array(&[m[0] as f32, m[1] as f32, m[2] as f32, m[3] as f32, m[4] as f32, m[5] as f32, m[6] as f32, m[7] as f32, m[8] as f32]);
// let roi_corners_mat = Mat::from_slice(world_corners)?;
// let dst_corners_mat = Mat::from_slice(Corner::in_laser_space())?;
// let matrix = imgproc::get_perspective_transform(&roi_corners_mat, &dst_corners_mat)?;
// dbg!(&m, &mat);
config.filters.homography.homography_matrix = mat;
// let matches = vec![
// FeatureMatch(Point2::new(0.0, 0.0), Point2::new(0.0, 2.0)),
// FeatureMatch(Point2::new(1.0, 1.0), Point2::new(1.0, 3.0)),
// FeatureMatch(Point2::new(2.0, 4.0), Point2::new(2.0, 6.0)),
// FeatureMatch(Point2::new(7.0, 3.0), Point2::new(7.0, 5.0)),
// ];
}
fn map_mouse_pressed(app: &App, model: &mut GuiModel, button: MouseButton) {