Tracking objects in video

Detection tells you where things are in one frame. Tracking tells you which thing is which across frames.

4 min read

Why detection alone is not enough

Run a detector on every frame of a video and you get a new list of boxes each time, with no link between them. Counting cars that pass would count the same car in every frame.

What a tracker adds

A tracker predicts where each known object should be in the next frame and matches the new detections to those predictions. A matched object keeps its ID; a new one gets a new ID; an object that disappears for long enough is dropped.

Good detections make good tracks. Because fotonet returns one box per object with no duplicates, the tracker has less noise to sort out.

Tracking with fotonet

from fotonet import Fotonet

model = Fotonet("fotonetn")
for result in model.track("traffic.mp4", tracker="bytetrack", stream=True):
    for box in result.boxes:
        print(box.id, box.cls, box.xyxy)

Each box now carries an id. The default tracker matches boxes by overlap and is very light; bytetrack also predicts motion and copes better with fast objects and brief misses. Pass classes=["car"] to follow only the classes you care about.

Frames from a camera

For live input, read frames with OpenCV and pass them as they are: model.predict_bgr(frame) takes OpenCV's BGR images directly, with no conversion.