use core::{
borrow::Borrow,
fmt::Debug,
};
use sophus_autodiff::params::IsParamsImpl;
use sophus_image::ImageSize;
use crate::{
BrownConradyCamera,
KannalaBrandtCamera,
PinholeCamera,
camera_enum::EnhancedUnifiedCamera,
prelude::*,
};
pub trait IsCameraDistortionImpl<
S: IsScalar<BATCH, DM, DN>,
const DISTORT: usize,
const PARAMS: usize,
const BATCH: usize,
const DM: usize,
const DN: usize,
>: IsParamsImpl<S, PARAMS, BATCH, DM, DN> + Debug + Clone + Send + Sync + 'static
{
fn identity_params() -> S::Vector<PARAMS> {
let mut params = S::Vector::<PARAMS>::zeros();
*params.elem_mut(0) = S::ones();
*params.elem_mut(1) = S::ones();
params
}
fn distort<PA, PO>(params: PA, proj_point_in_camera_z1_plane: PO) -> S::Vector<2>
where
PA: Borrow<S::Vector<PARAMS>>,
PO: Borrow<S::Vector<2>>;
fn undistort<PA, PO>(params: PA, distorted_point: PO) -> S::Vector<2>
where
PA: Borrow<S::Vector<PARAMS>>,
PO: Borrow<S::Vector<2>>;
fn dx_distort_x<PA, PO>(params: PA, proj_point_in_camera_z1_plane: PO) -> S::Matrix<2, 2>
where
PA: Borrow<S::Vector<PARAMS>>,
PO: Borrow<S::Vector<2>>;
fn dx_distort_params<PA, PO>(
params: PA,
proj_point_in_camera_z1_plane: PO,
) -> S::Matrix<2, PARAMS>
where
PA: Borrow<S::Vector<PARAMS>>,
PO: Borrow<S::Vector<2>>;
}
pub trait IsProjection<
S: IsScalar<BATCH, DM, DN>,
const BATCH: usize,
const DM: usize,
const DN: usize,
>: Debug + Clone + Send + Sync + 'static
{
fn proj<P>(point_in_camera: P) -> S::Vector<2>
where
P: Borrow<S::Vector<3>>;
fn unproj<P>(point_in_camera: P, extension: S) -> S::Vector<3>
where
P: Borrow<S::Vector<2>>;
fn dx_proj_x<P>(point_in_camera: P) -> S::Matrix<2, 3>
where
P: Borrow<S::Vector<3>>;
}
pub trait IsCamera<
S: IsScalar<BATCH, DM, DN> + 'static + Send + Sync,
const BATCH: usize,
const DM: usize,
const DN: usize,
>
{
fn new_pinhole(params: S::Vector<4>, image_size: ImageSize) -> Self;
fn new_kannala_brandt(params: S::Vector<8>, image_size: ImageSize) -> Self;
fn new_brown_conrady(params: S::Vector<12>, image_size: ImageSize) -> Self;
fn new_enhanced_unified(params: S::Vector<6>, image_size: ImageSize) -> Self;
fn image_size(&self) -> ImageSize;
fn cam_proj<P>(&self, point_in_camera: P) -> S::Vector<2>
where
P: Borrow<S::Vector<3>>;
fn cam_unproj_with_z<P>(&self, pixel: P, z: S) -> S::Vector<3>
where
P: Borrow<S::Vector<2>>;
fn distort<P>(&self, proj_point_in_camera_z1_plane: P) -> S::Vector<2>
where
P: Borrow<S::Vector<2>>;
fn undistort<P>(&self, pixel: P) -> S::Vector<2>
where
P: Borrow<S::Vector<2>>;
fn dx_distort_x<P>(&self, proj_point_in_camera_z1_plane: P) -> S::Matrix<2, 2>
where
P: Borrow<S::Vector<2>>;
fn try_get_brown_conrady(self) -> Option<BrownConradyCamera<S, BATCH, DM, DN>>;
fn try_get_kannala_brandt(self) -> Option<KannalaBrandtCamera<S, BATCH, DM, DN>>;
fn try_get_pinhole(self) -> Option<PinholeCamera<S, BATCH, DM, DN>>;
fn try_get_enhanced_unified(self) -> Option<EnhancedUnifiedCamera<S, BATCH, DM, DN>>;
}
pub trait IsPerspectiveCamera<
S: IsScalar<BATCH, DM, DN>,
const BATCH: usize,
const DM: usize,
const DN: usize,
>
{
fn pinhole_params(&self) -> S::Vector<4>;
}