-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to print the results of people ID, coordinates of the box in each second as csv #11762
Comments
Hello! It sounds like you're looking to extract and save trajectory and tracking details into a CSV file at a specific frame rate. Here's a concise way to achieve this with the YOLOv8 model: You'll need to run the tracker, collect results, and then save the relevant data (ID, bounding box coordinates, frame number) to a CSV. import csv
from ultralytics import YOLO
# Load your model
model = YOLO('path/to/model.pt')
# Setting up CSV to save the data
with open('output.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerow(["Frame", "ID", "X", "Y", "Width", "Height"])
# Process video and track frame by frame
for frame_idx, (path, im, im0s, vid_cap, s) in enumerate(model.track(source='path/to/video.mp4', stream=True)):
if frame_idx % 20 == 0: # capture every 20 frames
for *xyxy, conf, cls, track_id in im0s["tracking"]:
if int(cls) == 0: # class '0' for people, change this based on your class labels
x1, y1, x2, y2 = map(int, xyxy)
width, height = x2 - x1, y2 - y1
writer.writerow([frame_idx, track_id, x1, y1, width, height])
# This script assumes that you are tracking 'people', as denoted by class '0'. This script will save every 20th frame's tracking info into |
Thank you so much! |
You're welcome! I'm glad I could help. If you have any more questions or need further assistance as you work with YOLOv8, feel free to ask. Happy coding! 😊 |
@ArielZhanghj hello! I'm here to help with your questions about tracking and trajectory analysis using YOLOv8. 😊
This method should help you visualize pedestrian paths effectively. If you need more detailed guidance or further assistance, feel free to ask. Happy tracking! 🚀 |
Search before asking
Question
After print the video results, I want to know how to print the identification results, and use these information to draw the trajectories and heat map in a period of time of the video.
I want to print the frame number, people ID, coordinates of the box... in each 20 frame (the frame rate of video is 20 f/s) as csv, which as shown in the figure.
Additional
No response
The text was updated successfully, but these errors were encountered: