Skip to content

Commit

Permalink
Merge pull request #1488 from mikel-brostrom/fix-kf-name
Browse files Browse the repository at this point in the history
xys now xysr kf
  • Loading branch information
mikel-brostrom committed Jun 20, 2024
2 parents 9863bd2 + f959fb5 commit dde696d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
25 changes: 17 additions & 8 deletions boxmot/motion/kalman_filters/xyah_kf.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,24 @@ def __init__(self):
super().__init__(ndim=4)

def _get_initial_covariance_std(self, measurement: np.ndarray) -> np.ndarray:
# initial uncertainty in the aspect ratio is very low,
# suggesting that it is not expected to vary significantly.
return [
2 * self._std_weight_position * measurement[3],
2 * self._std_weight_position * measurement[3],
1e-2,
2 * self._std_weight_position * measurement[3],
10 * self._std_weight_velocity * measurement[3],
10 * self._std_weight_velocity * measurement[3],
1e-5,
10 * self._std_weight_velocity * measurement[3]
2 * self._std_weight_position * measurement[3], # x
2 * self._std_weight_position * measurement[3], # y
1e-2, # a (aspect ratio)
2 * self._std_weight_position * measurement[3], # H
10 * self._std_weight_velocity * measurement[3], # vx
10 * self._std_weight_velocity * measurement[3], # vy
1e-5, # va (aspect ration vel)
10 * self._std_weight_velocity * measurement[3] # vh
]

def _get_process_noise_std(self, mean: np.ndarray) -> Tuple[np.ndarray, np.ndarray]:
# very small process noise standard deviation assigned to the
# aspect ratio state and its velocity. Suggests
# that the aspect ratio is expected to remain relatively constant
# over time.
std_pos = [
self._std_weight_position * mean[3],
self._std_weight_position * mean[3],
Expand All @@ -40,6 +46,9 @@ def _get_process_noise_std(self, mean: np.ndarray) -> Tuple[np.ndarray, np.ndarr
return std_pos, std_vel

def _get_measurement_noise_std(self, mean: np.ndarray, confidence: float) -> np.ndarray:
# small measurement noise standard deviation for
# aspect ratio state, indicating low expected measurement noise in
# the aspect ratio.
std_noise = [
self._std_weight_position * mean[3],
self._std_weight_position * mean[3],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -*- coding: utf-8 -*-
# pylint: disable=invalid-name, too-many-arguments, too-many-branches,
# pylint: disable=too-many-locals, too-many-instance-attributes, too-many-lines


"""
This module implements the linear Kalman filter in both an object
Expand Down Expand Up @@ -106,9 +104,9 @@
from filterpy.common import pretty_str, reshape_z
from collections import deque


# The aspect ratio r is assumed to be constant.
class KalmanFilterXYS(object):
# x_t is a seven-tuple, i.e. x_t =[u, v, s, r, u,˙ v,˙ s˙]^⊤,
# r (aspect ratio) is assumed to be constant.
class KalmanFilterXYSR(object):
""" Implements a Kalman filter. You are responsible for setting the
various state variables to reasonable values; the defaults will
not give you a functional filter.
Expand Down
4 changes: 2 additions & 2 deletions boxmot/trackers/deepocsort/deep_ocsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from boxmot.appearance.reid_auto_backend import ReidAutoBackend
from boxmot.motion.cmc import get_cmc_method
from boxmot.motion.kalman_filters.xys_kf import KalmanFilterXYS
from boxmot.motion.kalman_filters.xysr_kf import KalmanFilterXYSR
from boxmot.utils.association import associate, linear_assignment
from boxmot.utils.iou import get_asso_func
from boxmot.trackers.basetracker import BaseTracker
Expand Down Expand Up @@ -107,7 +107,7 @@ def __init__(self, det, delta_t=3, emb=None, alpha=0, new_kf=False, max_obs=50):
self.det_ind = det[6]

if new_kf:
self.kf = KalmanFilterXYS(dim_x=8, dim_z=4, max_obs=max_obs)
self.kf = KalmanFilterXYSR(dim_x=8, dim_z=4, max_obs=max_obs)
self.kf.F = np.array(
[
# x y w h x' y' w' h'
Expand Down
4 changes: 2 additions & 2 deletions boxmot/trackers/hybridsort/hybridsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ def __init__(
"""
# define constant velocity model
# if not orig and not args.kalman_GPR:
from boxmot.motion.kalman_filters.xys_kf import KalmanFilterXYS
self.kf = KalmanFilterXYS(dim_x=9, dim_z=5, max_obs=max_obs)
from boxmot.motion.kalman_filters.xysr_kf import KalmanFilterXYSR
self.kf = KalmanFilterXYSR(dim_x=9, dim_z=5, max_obs=max_obs)

# u, v, s, c, r, ~u, ~v, ~s, ~c
self.kf.F = np.array([[1, 0, 0, 0, 0, 1, 0, 0, 0],
Expand Down
4 changes: 2 additions & 2 deletions boxmot/trackers/ocsort/ocsort.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from collections import deque


from boxmot.motion.kalman_filters.xys_kf import KalmanFilterXYS
from boxmot.motion.kalman_filters.xysr_kf import KalmanFilterXYSR
from boxmot.utils.association import associate, linear_assignment
from boxmot.utils.iou import get_asso_func
from boxmot.utils.iou import run_asso_func
Expand Down Expand Up @@ -80,7 +80,7 @@ def __init__(self, bbox, cls, det_ind, delta_t=3, max_obs=50):
"""
# define constant velocity model
self.det_ind = det_ind
self.kf = KalmanFilterXYS(dim_x=7, dim_z=4, max_obs=max_obs)
self.kf = KalmanFilterXYSR(dim_x=7, dim_z=4, max_obs=max_obs)
self.kf.F = np.array(
[
[1, 0, 0, 0, 1, 0, 0],
Expand Down

0 comments on commit dde696d

Please sign in to comment.