Getting Bounding Box Information with live webcam #16578
Replies: 2 comments
-
👋 Hello @TanJingXuan-06, thank you for reaching out to Ultralytics 🚀! We're glad to see your interest in getting live bounding box information. For new users, we suggest visiting the Docs where you can explore various Python and CLI examples, which might already cover your use case. If this is a 🐛 Bug Report, please ensure you provide a minimum reproducible example to assist us in debugging. If you're facing a challenge with custom training or implementation, provide detailed information and confirm you're following our Tips for Best Training Results. For real-time interactivity, consider joining our community on Discord 🎧. Additionally, Discourse and our Subreddit are great places for more in-depth discussions. UpgradeTo ensure your issue is not already addressed, make sure you're using the latest pip install -U ultralytics EnvironmentsYOLOv8 operates seamlessly in any of the following environments:
StatusIf the badge above is green, all CI tests are passing, confirming proper operation across platforms. This is an automated response. An Ultralytics engineer will assist you shortly. Thank you for your patience 😊! |
Beta Was this translation helpful? Give feedback.
-
To continuously update bounding box information, place your detection and extraction code inside a loop that processes each frame from the webcam. This will ensure you receive live updates. |
Beta Was this translation helpful? Give feedback.
-
from ultralytics import YOLO
import cv2
Load your model
model = YOLO("C:/Users/user/Downloads/best.pt")
Perform object detection on webcam feed (source="0" refers to the default webcam)
results = model.predict(source=0, show=True)
Extract bounding boxes, classes, names, and confidences
boxes = results[0].boxes.xyxy.tolist()
classes = results[0].boxes.cls.tolist()
names = results[0].names
confidences = results[0].boxes.conf.tolist()
print("Hi")
Iterate through the results
for box, cls, conf in zip(boxes, classes, confidences):
x1, y1, x2, y2 = box
confidence = conf
detected_class = cls
name = names[int(cls)]
Hi, the above is my code, my code can detect the objects but I want to get a live update on the bounding box information. I want to constantly get the bounding box information while I am getting this output:
Beta Was this translation helpful? Give feedback.
All reactions