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
andmax_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
impl TouchDetector
Sourcepub fn new<Device: Data>(
device: &Device,
min_touch: f32,
max_touch: f32,
baseline_sample_size: usize,
sample_size: usize,
pixel_count: usize,
) -> Self
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.
Sourcepub fn process<Device: Data>(
&mut self,
device: &Device,
touch_signal: &mut [u8],
distance: &mut [f32],
)
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()
.
Sourcepub fn get_normalized_average_depth(&self, average_depth: &mut [u8])
pub fn get_normalized_average_depth(&self, average_depth: &mut [u8])
A by-product, returning only the normalized moving average of the depth.
Sourcepub fn get_baseline(&self) -> Vec<f32>
pub fn get_baseline(&self) -> Vec<f32>
The baseline depth as the average of the first baseline_sample_size
frames.