pub struct Camera<R, I>where
I: IntrinsicParameters<R>,
R: RealField,{ /* private fields */ }
Expand description
A camera model that can convert world coordinates into pixel coordinates.
§Examples
Creates a new perspective camera:
use cam_geom::*;
use nalgebra::*;
// perepective parameters - focal length of 100, no skew, pixel center at (640,480)
let intrinsics = IntrinsicParametersPerspective::from(PerspectiveParams {
fx: 100.0,
fy: 100.0,
skew: 0.0,
cx: 640.0,
cy: 480.0,
});
// Set extrinsic parameters - camera at (10,0,10), looing at (0,0,0), up (0,0,1)
let camcenter = Vector3::new(10.0, 0.0, 10.0);
let lookat = Vector3::new(0.0, 0.0, 0.0);
let up = Unit::new_normalize(Vector3::new(0.0, 0.0, 1.0));
let pose = ExtrinsicParameters::from_view(&camcenter, &lookat, &up);
// Create camera with both intrinsic and extrinsic parameters.
let cam = Camera::new(intrinsics, pose);
Creates a new orthographic camera:
use cam_geom::*;
use nalgebra::*;
// orthographic parameters - scale of 100, pixel center at (640,480)
let intrinsics = IntrinsicParametersOrthographic::from(OrthographicParams {
sx: 100.0,
sy: 100.0,
cx: 640.0,
cy: 480.0,
});
// Set extrinsic parameters - camera at (10,0,10), looing at (0,0,0), up (0,0,1)
let camcenter = Vector3::new(10.0, 0.0, 10.0);
let lookat = Vector3::new(0.0, 0.0, 0.0);
let up = Unit::new_normalize(Vector3::new(0.0, 0.0, 1.0));
let pose = ExtrinsicParameters::from_view(&camcenter, &lookat, &up);
// Create camera with both intrinsic and extrinsic parameters.
let cam = Camera::new(intrinsics, pose);
Implementations§
source§impl<R, I> Camera<R, I>where
I: IntrinsicParameters<R>,
R: RealField,
impl<R, I> Camera<R, I>where
I: IntrinsicParameters<R>,
R: RealField,
sourcepub fn new(intrinsics: I, extrinsics: ExtrinsicParameters<R>) -> Self
pub fn new(intrinsics: I, extrinsics: ExtrinsicParameters<R>) -> Self
Create a new camera from intrinsic and extrinsic parameters.
§Arguments
Intrinsic parameters and extrinsic parameters
sourcepub fn extrinsics(&self) -> &ExtrinsicParameters<R>
pub fn extrinsics(&self) -> &ExtrinsicParameters<R>
Return a reference to the extrinsic parameters.
sourcepub fn intrinsics(&self) -> &I
pub fn intrinsics(&self) -> &I
Return a reference to the intrinsic parameters.
sourcepub fn world_to_pixel<NPTS, InStorage>(
&self,
world: &Points<WorldFrame, R, NPTS, InStorage>
) -> Pixels<R, NPTS, Owned<R, NPTS, U2>>
pub fn world_to_pixel<NPTS, InStorage>( &self, world: &Points<WorldFrame, R, NPTS, InStorage> ) -> Pixels<R, NPTS, Owned<R, NPTS, U2>>
take 3D coordinates in world frame and convert to pixel coordinates
sourcepub fn pixel_to_world<IN, NPTS>(
&self,
pixels: &Pixels<R, NPTS, IN>
) -> RayBundle<WorldFrame, I::BundleType, R, NPTS, Owned<R, NPTS, U3>>
pub fn pixel_to_world<IN, NPTS>( &self, pixels: &Pixels<R, NPTS, IN> ) -> RayBundle<WorldFrame, I::BundleType, R, NPTS, Owned<R, NPTS, U3>>
take pixel coordinates and project to 3D in world frame
output arguments:
camera
- camera frame coordinate rays
world
- world frame coordinate rays
Note that the camera frame coordinates are returned as they must be computed anyway, so this additional data is “free”.
source§impl<R: RealField> Camera<R, IntrinsicParametersPerspective<R>>
impl<R: RealField> Camera<R, IntrinsicParametersPerspective<R>>
sourcepub fn from_perspective_matrix<S>(
pmat: &Matrix<R, U3, U4, S>
) -> Result<Self, Error>
pub fn from_perspective_matrix<S>( pmat: &Matrix<R, U3, U4, S> ) -> Result<Self, Error>
Create a Camera
from a 3x4 perspective projection matrix.
sourcepub fn as_camera_matrix(&self) -> SMatrix<R, 3, 4>
pub fn as_camera_matrix(&self) -> SMatrix<R, 3, 4>
Create a 3x4 perspective projection matrix modeling this camera.
Trait Implementations§
source§impl<'de, R, I> Deserialize<'de> for Camera<R, I>
impl<'de, R, I> Deserialize<'de> for Camera<R, I>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<R, I> PartialEq for Camera<R, I>
impl<R, I> PartialEq for Camera<R, I>
impl<R, I> StructuralPartialEq for Camera<R, I>where
I: IntrinsicParameters<R>,
R: RealField,
Auto Trait Implementations§
impl<R, I> Freeze for Camera<R, I>
impl<R, I> RefUnwindSafe for Camera<R, I>where
I: RefUnwindSafe,
R: RefUnwindSafe,
impl<R, I> Send for Camera<R, I>where
I: Send,
impl<R, I> Sync for Camera<R, I>where
I: Sync,
impl<R, I> Unpin for Camera<R, I>
impl<R, I> UnwindSafe for Camera<R, I>where
I: UnwindSafe,
R: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.