Sub topic 7
Creating, Confirming, and Deleting Tracks
This chapter assumes that you understand object-detection bounding boxes, IoU matching, and basic Python and NumPy. The association step tells us which detection belongs to which existing track. Track lifecycle management decides what happens before a track is reliable, when a detection is missed, and when an identity should be removed.
The three lifecycle states
A track usually moves through these states:
- Tentative: created from a recent detection but not trusted yet.
- Confirmed: matched often enough to represent a real object.
- Deleted: removed after evidence that the object has left the scene or can no longer be followed.
A new detection should not immediately become a confirmed identity. A false detection, sometimes called a false positive, might appear for only one frame. Requiring several successful matches prevents such noise from creating stable tracks.
A confirmed track can survive a short detection gap. During this period, the tracker coasts. It keeps the track alive using its last known box or a motion prediction. If detections do not return before the miss limit, the tracker deletes the track.
State transitions
A common policy uses two thresholds:
min_hits: matches required to confirm a tentative track.max_misses: consecutive unmatched frames allowed for a confirmed track.
The thresholds depend on the video. A high min_hits reduces false tracks but delays new IDs. A high max_misses handles brief occlusion but can leave stale tracks behind.
A minimal lifecycle manager
The code below assumes that a separate association algorithm has already produced assignments. Each assignment is a pair containing an existing track ID and the index of its matching detection.
class Track:
next_id = 1
def __init__(self, box):
self.id = Track.next_id
Track.next_id += 1
self.box = box
self.hits = 1
self.misses = 0
self.state = "tentative"
def matched(self, box, min_hits):
self.box = box
self.hits += 1
self.misses = 0
if self.hits >= min_hits:
self.state = "confirmed"
def missed(self, max_misses):
self.misses += 1
if self.state == "tentative" or self.misses > max_misses:
self.state = "deleted"
class TrackManager:
def __init__(self, min_hits=2, max_misses=2):
self.min_hits = min_hits
self.max_misses = max_misses
self.tracks = {}
def step(self, detections, assignments):
matched_track_ids = set()
matched_detection_ids = set()
for track_id, detection_id in assignments:
track = self.tracks[track_id]
track.matched(detections[detection_id], self.min_hits)
matched_track_ids.add(track_id)
matched_detection_ids.add(detection_id)
for track_id, track in self.tracks.items():
if track_id not in matched_track_ids:
track.missed(self.max_misses)
for detection_id, box in enumerate(detections):
if detection_id not in matched_detection_ids:
track = Track(box)
self.tracks[track.id] = track
self.tracks = {
track_id: track
for track_id, track in self.tracks.items()
if track.state != "deleted"
}
return [
(track.id, track.state, track.misses)
for track in self.tracks.values()
]
manager = TrackManager(min_hits=2, max_misses=2)
frames = [
([[10, 10, 50, 50]], []),
([[12, 10, 52, 50]], [(1, 0)]),
([], []),
([[18, 11, 58, 51]], [(1, 0)]),
]
for frame_number, (detections, assignments) in enumerate(frames, 1):
print(frame_number, manager.step(detections, assignments))The first detection creates a tentative track. The second matching detection confirms it. The empty third frame causes one miss, so the track coasts. The fourth detection returns and resets the miss counter.
Practical decisions
Use a stricter confirmation rule when detector false positives are common. Use a longer miss allowance when objects are often hidden briefly. However, a long allowance can cause an old track to take the identity of a new object after the original object leaves.
Track lifecycle logic also needs special handling for:
- tracks that overlap during occlusion,
- detections that match multiple tracks,
- tracks that leave the camera view,
- sudden camera motion that makes old boxes unreliable.
Exercise
With minhits = 3 and maxmisses = 2, what happens to a new track after one detection, one matching detection, and then one missed frame?
Show answer
It remains tentative and is deleted on the missed frame. It has only two hits, and tentative tracks are not allowed to survive a miss in this policy.