Skip to main content

StereoCameraSystem

Struct StereoCameraSystem 

Source
pub struct StereoCameraSystem {
    pub left: CameraIntrinsics,
    pub right: CameraIntrinsics,
    pub baseline: f64,
    pub r: [[f64; 3]; 3],
    pub t: [f64; 3],
}
Expand description

A stereo camera rig consisting of left and right pinhole cameras.

The stereo geometry is described by a relative rotation R and translation T such that a point P_l in the left-camera frame maps to the right frame as P_r = R * P_l + T.

For a typical horizontal stereo setup T ≈ [-baseline, 0, 0].

Fields§

§left: CameraIntrinsics

Left camera intrinsics.

§right: CameraIntrinsics

Right camera intrinsics.

§baseline: f64

Baseline distance between optical centres (metres).

§r: [[f64; 3]; 3]

Rotation from left to right camera frame.

§t: [f64; 3]

Translation from left to right camera frame (metres).

Implementations§

Source§

impl StereoCameraSystem

Source

pub fn new( left: CameraIntrinsics, right: CameraIntrinsics, r: [[f64; 3]; 3], t: [f64; 3], ) -> Self

Create a new stereo system. The baseline is derived from ‖T‖.

Source

pub fn disparity_to_depth(&self, disparity: f64) -> Option<f64>

Convert disparity to metric depth using depth = baseline * fx / disparity.

Returns None when disparity ≤ 0.

let cam = CameraIntrinsics::ideal(800.0, 800.0, 320.0, 240.0);
let stereo = StereoCameraSystem::new(
    cam.clone(), cam,
    [[1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0]],
    [-0.1, 0.0, 0.0],
);
let depth = stereo.disparity_to_depth(80.0).unwrap();
assert!((depth - 1.0).abs() < 1e-9);
Source

pub fn triangulate( &self, left_px: [f64; 2], right_px: [f64; 2], ) -> Option<[f64; 3]>

Triangulate a 3-D point from stereo pixel correspondences using the Direct Linear Transform (mid-point method on the two rays).

Both pixels are assumed to be in a rectified coordinate frame so that epipolar lines are horizontal.

Returns None when the rays are nearly parallel.

let cam = CameraIntrinsics::ideal(800.0, 800.0, 320.0, 240.0);
let stereo = StereoCameraSystem::new(
    cam.clone(), cam,
    [[1.0,0.0,0.0],[0.0,1.0,0.0],[0.0,0.0,1.0]],
    [-0.1, 0.0, 0.0],
);
// A point at (0, 0, 1 m): left pixel = (320, 240), right pixel = (240, 240)
let pt = stereo.triangulate([320.0, 240.0], [240.0, 240.0]).unwrap();
assert!((pt[2] - 1.0).abs() < 0.05);
Source

pub fn compute_disparity_map( &self, left_img: &[Vec<f64>], right_img: &[Vec<f64>], max_disparity: usize, block_size: usize, ) -> Vec<Vec<f64>>

Compute a disparity map from a rectified stereo pair using block matching.

Both images must have the same dimensions. Returns a disparity map of identical dimensions; pixels where no match was found carry value 0.0.

§Arguments
  • left_img – Row-major grayscale image [row][col].
  • right_img – Row-major grayscale image [row][col].
  • max_disparity – Maximum disparity to search (pixels).
  • block_size – Half-window radius (full window = 2r+1 × 2r+1).

Trait Implementations§

Source§

impl Clone for StereoCameraSystem

Source§

fn clone(&self) -> StereoCameraSystem

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for StereoCameraSystem

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more