File size: 597 Bytes
d1f37f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b1a7fa2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import cv2
from ultralytics import YOLO
from ultralytics.utils.plotting import Annotator


model = YOLO("my_model.pt")

# Run inference
results = model("datasets/socker/valid/images/img_307_jpeg.rf.8ee20e9d3ea38fa3a62c2495e7e824e3.jpg", imgsz=1920)
print(results)

# Draw bounding boxes on the image
result = results[0]

annotator = Annotator(result.orig_img, line_width=3)
boxes = result.boxes
for box in boxes:
    b = box.xyxy[0]
    c = box.cls
    annotator.box_label(b, model.names[int(c)], color=(0, 0, 255))


img = annotator.result()  
cv2.imshow('YOLO V8 Detection', img)
cv2.waitKey(0)