-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |