Back to Module
Computer Vision
Courses & Resources
Code Demos
Object Detection with YOLOv8
使用 YOLOv8 进行实时目标检测,适用于机器人感知
python
from ultralytics import YOLO
import cv2
# Load pretrained model
model = YOLO("yolov8n.pt")
# Run inference on image
results = model("robot_workspace.jpg")
# Display results
for result in results:
boxes = result.boxes
for box in boxes:
cls = int(box.cls[0])
conf = float(box.conf[0])
print(f"Detected: {model.names[cls]} ({conf:.2f})")
# Visualize
result.show()