Pyhtagodzilla a13a74a87d init
2025-09-28 23:50:13 +08:00

29 lines
816 B
Python

import cv2
from ultralytics import YOLO
model = YOLO(r'models/yolo11x.pt')
image = cv2.imread(r'resources/gooes.jpg')
if image is None:
print("Could not read the image.")
exit()
else:
results = model(image, conf=0.5)
for r in results:
boxes = r.boxes
for box in boxes:
x1, y1, x2, y2 = box.xyxy[0].int().tolist()
class_id = int(box.cls[0])
confidence = float(box.conf[0])
class_name = model.names[class_id]
cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
label = f'{class_name} {confidence:.2f}'
cv2.putText(image, label, (x1, y1 - 10),cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.imshow('YOLOv10 Detection', image)
cv2.waitKey(0)
cv2.destroyAllWindows()