computervisioneng / object-tracking-yolov8-deep-sort

93 stars 58 forks source link

Tracker.update(frame, detections) generates error when zero length detections is passed (no detection on the current frame) #9

Closed sweetagar closed 1 year ago

sweetagar commented 1 year ago

File "/Users/[path]/tracker.py", line 30, in update bboxes[:, 2:] = bboxes[:, 2:] - bboxes[:, 0:2] IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

It happens whenever there is no detection, guess need to add a check for empty detections list.

computervisioneng commented 1 year ago

Ok, noted.

Txavo commented 1 year ago
def update(self, frame, detections):

    if len(detections) == 0:
        self.tracker.predict()
        self.tracker.update([])  
        self.update_tracks()
        return

    bboxes = np.asarray([d[:-1] for d in detections])
    bboxes[:, 2:] = bboxes[:, 2:] - bboxes[:, 0:2]
    scores = [d[-1] for d in detections]
    features = self.encoder(frame, bboxes)
    dets = []
    for bbox_id, bbox in enumerate(bboxes):
        dets.append(Detection(bbox, scores[bbox_id], features[bbox_id]))

    self.tracker.predict()
    self.tracker.update(dets)
    self.update_tracks()
computervisioneng commented 1 year ago

I sent a commit with the edit.