mikel-brostrom / boxmot

BoxMOT: pluggable SOTA tracking modules for segmentation, object detection and pose estimation models
GNU Affero General Public License v3.0
6.71k stars 1.71k forks source link

What should I do when there is no detection #1513

Closed gigasurgeon closed 3 months ago

gigasurgeon commented 3 months ago

Search before asking

Question

I am tracking players in basketball using bytetracker. In few frames of the video, there are no players. Should I still update the tracker? Or should I only update the tracker when there are detections?

mikel-brostrom commented 3 months ago

You should keep updating the tracker, as I will make predictions to compensate for the missing detections. This will ensure that the tracks can catch up with the detections once they resume.

gigasurgeon commented 3 months ago

How should I update the tracker if there are no detection in that frame? I tried tracker_dets = tracker.update(None, None) and also tracker_dets = tracker.update(np.array([[]], None), and both are giving errors. Is there a way to update tracker with no dets?

mikel-brostrom commented 3 months ago

Here comes an example 😄

from pathlib import Path
from boxmot import DeepOCSORT
import cv2
import numpy as np

tracker = DeepOCSORT(
    model_weights=Path('osnet_x0_25_msmt17.pt'), # which ReID model to use
    device='cpu',
    fp16=False,
)

vid = cv2.VideoCapture(0)

while True:
    ret, im = vid.read()

    # empty N X (x, y, x, y, conf, cls)
    dets = np.empty((0, 6))

    tracker.update(dets, im) # --> M X (x, y, x, y, id, conf, cls, ind)
    tracker.plot_results(im, show_trajectories=True)
    print("UPDATED!")

    # break on pressing q or space
    cv2.imshow('BoxMOT detection', im)     
    key = cv2.waitKey(1) & 0xFF
    if key == ord(' ') or key == ord('q'):
        break

vid.release()
cv2.destroyAllWindows()
gigasurgeon commented 3 months ago

thanks for the example. dets = np.empty((0, 6)) did the trick.

mikel-brostrom commented 3 months ago

Added this to the detection example under README. Thanks for pointing this out @gigasurgeon!