pub struct FloatTrackerContext { /* private fields */ }Expand description
Pyramidal Lucas-Kanade tracker for f32 images in physical units, e.g.
thermal frames in °C. The counterpart of TrackerContext, owning both
frame pyramids and every buffer the tracking hot path touches.
The algorithm and its parameters match the 8-bit tracker: pyramids of
2x2 means, Scharr gradients, bilinear window sampling, the same
convergence rules, prediction and forward-backward check, and the same
TrackResult and TrackStatus. Pixels, pyramids and gradients stay
in f32 throughout; nothing is quantized. The pyramid averages exactly
instead of truncating like the 8-bit pyramid, so on the same frames the
two trackers agree closely but not bit for bit.
Units follow the image:
TrackParams::min_eigen_thresholdis in (input unit / pixel)^2, the unit of the f32 detector’s scores, and has no default. A window whose mean minimum gradient eigenvalue is below it isTrackStatus::LowTexture. Windows whose eigenvalue ratio is below f32 resolution are low texture as well, at any contrast: the singularity test is relative, so small physical gradients still track.TrackResult::erroris the mean absolute residual in the input unit.- Positions,
fb_thresholdandCONVERGENCE_EPSILONare in pixels.
Per frame, call advance with the new frame, or
prepare with a frame pair, as for TrackerContext.
Create the context with with_capacity to keep
allocation out of the per-frame path.
Implementations§
Source§impl FloatTrackerContext
impl FloatTrackerContext
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty context. Buffers grow to fit on the first call and are reused thereafter.
Sourcepub fn with_capacity(capacity: TrackerCapacity) -> Self
pub fn with_capacity(capacity: TrackerCapacity) -> Self
Creates a context with every buffer allocated for capacity.
Sourcepub fn reserve(&mut self, capacity: TrackerCapacity)
pub fn reserve(&mut self, capacity: TrackerCapacity)
Allocates every buffer for capacity now, so that later calls within
it do not allocate. Existing capacity is kept.
Sourcepub fn prepare(
&mut self,
prev: FloatImageView<'_>,
next: FloatImageView<'_>,
levels: usize,
)
pub fn prepare( &mut self, prev: FloatImageView<'_>, next: FloatImageView<'_>, levels: usize, )
Builds the previous- and next-frame pyramids with up to levels
levels; halving stops below 2 pixels.
§Panics
Panics if the two frames differ in size.
Sourcepub fn advance(&mut self, frame: FloatImageView<'_>, levels: usize)
pub fn advance(&mut self, frame: FloatImageView<'_>, levels: usize)
Moves to the next frame pair: the pyramid of the last next frame
becomes the previous-frame pyramid, by swapping buffers, and the
next-frame pyramid is built from frame. The results equal those of
prepare(last_next, frame, levels) bit for bit with one pyramid build
instead of two, and the steady state performs no heap allocation.
Without a reusable last frame, the pyramids are built as described
for TrackerContext::advance.
Sourcepub fn prev_pyramid(&self) -> &[FloatPyramidLevel] ⓘ
pub fn prev_pyramid(&self) -> &[FloatPyramidLevel] ⓘ
Sourcepub fn next_pyramid(&self) -> &[FloatPyramidLevel] ⓘ
pub fn next_pyramid(&self) -> &[FloatPyramidLevel] ⓘ
Sourcepub fn track(
&mut self,
prev_points: &[(f32, f32)],
predicted: Option<&[(f32, f32)]>,
params: TrackParams,
) -> &[TrackResult]
pub fn track( &mut self, prev_points: &[(f32, f32)], predicted: Option<&[(f32, f32)]>, params: TrackParams, ) -> &[TrackResult]
Tracks prev_points from the previous into the next frame, as
calc_optical_flow_ex does. params.min_eigen_threshold is in
(input unit / pixel)^2. Returns one result per point, in order, from
the context’s own buffer.
§Panics
Panics if prepare was not called, params.window_size is even, or
predicted has a different length than prev_points.
Sourcepub fn track_with(
&mut self,
prev_points: &[(f32, f32)],
predicted: Option<&[(f32, f32)]>,
params: TrackParams,
options: TrackOptions,
) -> &[TrackResult]
pub fn track_with( &mut self, prev_points: &[(f32, f32)], predicted: Option<&[(f32, f32)]>, params: TrackParams, options: TrackOptions, ) -> &[TrackResult]
track with TrackOptions. The f32 tracker always
uses its f32 kernels, so only start_level applies.
Sourcepub fn track_fb(
&mut self,
prev_points: &[(f32, f32)],
predicted: Option<&[(f32, f32)]>,
params: TrackParams,
fb_threshold: f32,
) -> &[TrackResult]
pub fn track_fb( &mut self, prev_points: &[(f32, f32)], predicted: Option<&[(f32, f32)]>, params: TrackParams, fb_threshold: f32, ) -> &[TrackResult]
Forward-backward consistent tracking, as calc_optical_flow_fb
does; fb_threshold is in pixels.
§Panics
As track.
Sourcepub fn track_fb_with(
&mut self,
prev_points: &[(f32, f32)],
predicted: Option<&[(f32, f32)]>,
params: TrackParams,
fb_threshold: f32,
options: TrackOptions,
) -> &[TrackResult]
pub fn track_fb_with( &mut self, prev_points: &[(f32, f32)], predicted: Option<&[(f32, f32)]>, params: TrackParams, fb_threshold: f32, options: TrackOptions, ) -> &[TrackResult]
track_fb with TrackOptions: the level the
forward pass starts at and the levels of the backward pass.
§Panics
As track, and if options.fb_levels is Some(0).