From 19a7a052cba32945625de13bf0f9e9da404ecd26 Mon Sep 17 00:00:00 2001 From: Jake Silver Date: Tue, 26 Sep 2023 18:55:51 -0400 Subject: [PATCH] added botsort file --- src/botsort.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/botsort.py diff --git a/src/botsort.py b/src/botsort.py new file mode 100644 index 00000000..9638f573 --- /dev/null +++ b/src/botsort.py @@ -0,0 +1,36 @@ +import cv2 +from ultralytics import YOLO + +# Load the YOLOv8 model +model = YOLO('yolov8n.pt') + +# Open the video file +video_path = "test2_10seconds.mp4" +cap = cv2.VideoCapture(video_path) + +# Loop through the video frames +while cap.isOpened(): + # Read a frame from the video + success, frame = cap.read() + + if success: + # Run YOLOv8 tracking on the frame, persisting tracks between frames + # change tracker to botsort.yaml or bytetrack.yaml + results = model.track(frame, persist=True, tracker="bytetrack.yaml") + + # Visualize the results on the frame + annotated_frame = results[0].plot() + + # Display the annotated frame + cv2.imshow("YOLOv8 Tracking", annotated_frame) + + # Break the loop if 'q' is pressed + if cv2.waitKey(1) & 0xFF == ord("q"): + break + else: + # Break the loop if the end of the video is reached + break + +# Release the video capture object and close the display window +cap.release() +cv2.destroyAllWindows()