MCPcopy Create free account
hub / github.com/Vegetebird/GraphMLP / KalmanBoxTracker

Class KalmanBoxTracker

demo/lib/sort/sort.py:61–122  ·  view source on GitHub ↗

This class represents the internel state of individual tracked objects observed as bbox.

Source from the content-addressed store, hash-verified

59
60
61class KalmanBoxTracker(object):
62 """
63 This class represents the internel state of individual tracked objects observed as bbox.
64 """
65 count = 0
66
67 def __init__(self, bbox):
68 """
69 Initialises a tracker using initial bounding box.
70 """
71 # define constant velocity model
72 self.kf = KalmanFilter(dim_x=7, dim_z=4)
73 self.kf.F = np.array(
74 [[1, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 0, 1, 0], [0, 0, 1, 0, 0, 0, 1], [0, 0, 0, 1, 0, 0, 0],
75 [0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 1]])
76 self.kf.H = np.array(
77 [[1, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0]])
78
79 self.kf.R[2:, 2:] *= 10.
80 self.kf.P[4:, 4:] *= 1000. # give high uncertainty to the unobservable initial velocities
81 self.kf.P *= 10.
82 self.kf.Q[-1, -1] *= 0.01
83 self.kf.Q[4:, 4:] *= 0.01
84
85 self.kf.x[:4] = convert_bbox_to_z(bbox)
86 self.time_since_update = 0
87 self.id = KalmanBoxTracker.count
88 KalmanBoxTracker.count += 1
89 self.history = []
90 self.hits = 0
91 self.hit_streak = 0
92 self.age = 0
93
94 def update(self, bbox):
95 """
96 Updates the state vector with observed bbox.
97 """
98 self.time_since_update = 0
99 self.history = []
100 self.hits += 1
101 self.hit_streak += 1
102 self.kf.update(convert_bbox_to_z(bbox))
103
104 def predict(self):
105 """
106 Advances the state vector and returns the predicted bounding box estimate.
107 """
108 if ((self.kf.x[6] + self.kf.x[2]) <= 0):
109 self.kf.x[6] *= 0.0
110 self.kf.predict()
111 self.age += 1
112 if (self.time_since_update > 0):
113 self.hit_streak = 0
114 self.time_since_update += 1
115 self.history.append(convert_x_to_bbox(self.kf.x))
116 return self.history[-1]
117
118 def get_state(self):

Callers 1

updateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected