MCPcopy Create free account
hub / github.com/FoundationVision/ByteTrack / KalmanBoxTracker

Class KalmanBoxTracker

yolox/sort_tracker/sort.py:83–140  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

81
82
83class KalmanBoxTracker(object):
84 """
85 This class represents the internal state of individual tracked objects observed as bbox.
86 """
87 count = 0
88 def __init__(self,bbox):
89 """
90 Initialises a tracker using initial bounding box.
91 """
92 #define constant velocity model
93 self.kf = KalmanFilter(dim_x=7, dim_z=4)
94 self.kf.F = np.array([[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], [0,0,0,0,1,0,0],[0,0,0,0,0,1,0],[0,0,0,0,0,0,1]])
95 self.kf.H = np.array([[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]])
96
97 self.kf.R[2:,2:] *= 10.
98 self.kf.P[4:,4:] *= 1000. #give high uncertainty to the unobservable initial velocities
99 self.kf.P *= 10.
100 self.kf.Q[-1,-1] *= 0.01
101 self.kf.Q[4:,4:] *= 0.01
102
103 self.kf.x[:4] = convert_bbox_to_z(bbox)
104 self.time_since_update = 0
105 self.id = KalmanBoxTracker.count
106 KalmanBoxTracker.count += 1
107 self.history = []
108 self.hits = 0
109 self.hit_streak = 0
110 self.age = 0
111
112 def update(self,bbox):
113 """
114 Updates the state vector with observed bbox.
115 """
116 self.time_since_update = 0
117 self.history = []
118 self.hits += 1
119 self.hit_streak += 1
120 self.kf.update(convert_bbox_to_z(bbox))
121
122 def predict(self):
123 """
124 Advances the state vector and returns the predicted bounding box estimate.
125 """
126 if((self.kf.x[6]+self.kf.x[2])<=0):
127 self.kf.x[6] *= 0.0
128 self.kf.predict()
129 self.age += 1
130 if(self.time_since_update>0):
131 self.hit_streak = 0
132 self.time_since_update += 1
133 self.history.append(convert_x_to_bbox(self.kf.x))
134 return self.history[-1]
135
136 def get_state(self):
137 """
138 Returns the current bounding box estimate.
139 """
140 return convert_x_to_bbox(self.kf.x)

Callers 1

updateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected