Struct TouchDetector

Source
pub struct TouchDetector { /* private fields */ }
Expand description

The touch detector uses depth data to calculate the difference between the current depth and an initially recorded baseline depth. If this difference is between min_touch and max_touch a touch is assumed.

  • min_depth and max_depth are the measuring ranges of the depth camera in mm.
  • min_touch is the minimum height in mm above the surface considered to be a touch. If this parameter is too small, noise will lead to a lot of false detections.
  • max_touch is the maximum height in mm above the surface considered to be a touch.

First, an average baseline depth is computed using the first baseline_sample_size frames. The current depth is estimated by a moving average of sample_size frames.

Implementations§

Source§

impl TouchDetector

Source

pub fn new<Device: Data>( device: &Device, min_touch: f32, max_touch: f32, baseline_sample_size: usize, sample_size: usize, pixel_count: usize, ) -> Self

Creates a new instance with the specified parameters. All length parameters are in mm.

Source

pub fn process<Device: Data>( &mut self, device: &Device, touch_signal: &mut [u8], distance: &mut [f32], )

Processes a depth frame resulting in a touch_signal (255 for “touch”, 0 otherwise) and a distance from the initially measured depth in mm.

Note: This function does nothing if the current frame in device is not a depth frame. Call get_depth_mm_u16_frame() or get_depth_scaled_u8_frame() before calling process().

Source

pub fn get_normalized_average_depth(&self, average_depth: &mut [u8])

A by-product, returning only the normalized moving average of the depth.

Source

pub fn get_baseline(&self) -> Vec<f32>

The baseline depth as the average of the first baseline_sample_size frames.

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.