Skip to main content

FloatTrackerContext

Struct FloatTrackerContext 

Source
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_threshold is 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 is TrackStatus::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::error is the mean absolute residual in the input unit.
  • Positions, fb_threshold and CONVERGENCE_EPSILON are 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

Source

pub fn new() -> Self

Creates an empty context. Buffers grow to fit on the first call and are reused thereafter.

Source

pub fn with_capacity(capacity: TrackerCapacity) -> Self

Creates a context with every buffer allocated for capacity.

Source

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.

Source

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.

Source

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.

Source

pub fn prev_pyramid(&self) -> &[FloatPyramidLevel] ⓘ

The previous-frame pyramid built by the last prepare or advance.

Source

pub fn next_pyramid(&self) -> &[FloatPyramidLevel] ⓘ

The next-frame pyramid built by the last prepare or advance.

Source

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.

Source

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.

Source

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.

Source

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

Trait Implementations§

Source§

impl Default for FloatTrackerContext

Source§

fn default() -> Self

Returns the “default value” for a type. 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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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.