abewley / sort

Simple, online, and realtime tracking of multiple objects in a video sequence.
GNU General Public License v3.0
3.82k stars 1.07k forks source link

SORT / DSORT for live video feed #113

Open utsembedded opened 3 years ago

utsembedded commented 3 years ago

HI ,

How can i use this application to track objects using my camera with live feed .

software3daerospace commented 3 years ago

Hello, Assuming your object detection works, you can use this skeleton code to implement tracking on a live video:

import sort, cv2, numpy

def main():

    cap = cv2.VideoCapture(0)   # Open the webcam feed

    tracker = sort.Sort(max_age=0.5, min_hits=0.5, iou_threshold=0.5)

    # Load your object detector network here

    while True:

        img = cap.read()

        # perform your detections + NMS here
        # Store the detections in the Sort acceptable format. E.g. for Darknet, 
        # I get bounding boxes + confidence scores

        # Here I am assuming detections is formatted as a numpy array of: [[x1, y1, x2, y2, confidence]].
        tracks = tracker.update(detections)

        # tracks gives you a 2D numpy array in the format [[x1, y1, x2, y2, tracked_id]]

        # Add your display code here
    cap.release()):
Momilijaz96 commented 2 years ago

But are we making detections on every single frame? then what is the point of using tracker? How can we get updating bounding box locations using tracker without passing detections?