Skip to main content

ConstantVelocityXYAHModel2

Struct ConstantVelocityXYAHModel2 

Source
pub struct ConstantVelocityXYAHModel2<R>{
    pub mean: SVector<R, 8>,
    pub std_weight_position: R,
    pub std_weight_velocity: R,
    pub update_factor: R,
    pub covariance: OMatrix<R, U8, U8>,
    /* private fields */
}
Expand description

Constant-velocity Kalman filter for tracking a bounding box in XYAH space.

The state vector is [x, y, a, h, ẋ, ẏ, ȧ, ḣ] (8 dimensions):

ComponentMeaning
xCentre x coordinate
yCentre y coordinate
aAspect ratio (width / height), kept > 0 by a small epsilon floor
hHeight
ẋ, ẏ, ȧ, ḣFirst derivatives of the position components

Measurements arriving via update are in 4-dimensional XYAH space (no velocity), projected from the 8-D state by the observation matrix H. The filter uses a scale-adaptive process-noise covariance: noise magnitude scales proportionally with the box height h, so fast-moving large objects tolerate wider uncertainty than small static ones.

This is the same Kalman filter parameterisation used in the original ByteTrack paper (Zhang et al., 2022).

Fields§

§mean: SVector<R, 8>

Current state estimate: [x, y, a, h, ẋ, ẏ, ȧ, ḣ].

§std_weight_position: R

Scale factor for position noise (1/20 by default). Process noise for position components is std_weight_position * h.

§std_weight_velocity: R

Scale factor for velocity noise (1/160 by default). Process noise for velocity components is std_weight_velocity * h.

§update_factor: R

Measurement-to-innovation scaling applied in update. Set via ByteTrackBuilder::track_update. Values in (0, 1]; lower → smoother (trusts prediction more).

§covariance: OMatrix<R, U8, U8>

Current state covariance matrix P (8×8). Grows on each predict and shrinks on each update.

Implementations§

Source§

impl<R> ConstantVelocityXYAHModel2<R>
where R: RealField + Copy,

Source

pub fn new(measurement: &[R; 4], update_factor: R) -> Self

Initialise the filter from the first observation.

measurement is [x, y, a, h] in XYAH space. Velocity components are initialised to zero. The initial covariance is set proportionally to the box height so larger boxes start with wider uncertainty.

update_factor is stored and applied as a measurement gain in update.

Source

pub fn predict(&mut self)

Advance the filter by one time step with no measurement.

Applies the constant-velocity motion model (mean' = F * mean, cov' = F * cov * Fᵀ + Q) using a scale-adaptive process-noise covariance Q proportional to the current box height. Called once per frame for every active tracklet before the assignment step.

Source

pub fn project(&self) -> (OMatrix<R, U4, U1>, OMatrix<R, U4, U4>)

Project the 8-D state into 4-D measurement space.

Returns (projected_mean, projected_covariance) — the expected measurement and its uncertainty under the current state estimate. Used by update and by gating_distance.

Source

pub fn update(&mut self, measurement: &[R; 4])

Correct the state estimate with a new measurement.

measurement is [x, y, a, h] in XYAH space, as produced by xyxy_to_xyah in the ByteTrack update loop.

The Kalman gain is computed via Cholesky decomposition of the projected covariance. If the decomposition fails (degenerate covariance) the update is silently skipped and the prior state is preserved.

The innovation is scaled by self.update_factor before being applied, which effectively attenuates the correction — lower values produce smoother trajectories at the cost of slower response to abrupt motion.

Source

pub fn gating_distance( &self, measurements: &OMatrix<R, Dyn, U4>, only_position: bool, metric: GatingDistanceMetric, ) -> DVector<R>

Compute per-measurement gating distances from the current state.

Returns a vector of one scalar per row in measurements. Each scalar is either the squared Euclidean distance (GatingDistanceMetric::Gaussian) or the Mahalanobis distance (GatingDistanceMetric::Mahalanobis) from the projected state mean to that measurement.

only_position restricts the comparison to the first two components (x, y), ignoring aspect and height.

Not used by the current ByteTrack integration (which gates via IoU); exposed for future association strategies.

Trait Implementations§

Source§

impl<R> Clone for ConstantVelocityXYAHModel2<R>

Source§

fn clone(&self) -> ConstantVelocityXYAHModel2<R>

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<R> Debug for ConstantVelocityXYAHModel2<R>

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