vision_calibration_core/models/
projection.rs1use nalgebra::{Point2, RealField, Vector3};
2use serde::{Deserialize, Serialize};
3
4pub trait ProjectionModel<S: RealField + Copy> {
6 fn project_dir(&self, dir_c: &Vector3<S>) -> Option<Point2<S>>;
10 fn unproject_dir(&self, n: &Point2<S>) -> Vector3<S>;
12}
13
14#[derive(Clone, Copy, Debug, Default, Serialize, Deserialize)]
16pub struct Pinhole;
17
18impl<S: RealField + Copy> ProjectionModel<S> for Pinhole {
19 fn project_dir(&self, dir_c: &Vector3<S>) -> Option<Point2<S>> {
20 if dir_c.z <= S::zero() {
21 return None;
22 }
23 Some(Point2::new(dir_c.x / dir_c.z, dir_c.y / dir_c.z))
24 }
25
26 fn unproject_dir(&self, n: &Point2<S>) -> Vector3<S> {
27 Vector3::new(n.x, n.y, S::one())
28 }
29}