File size: 891 Bytes
70ebc90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
from ultralytics import YOLO
import cv2

# -------------------------------
# Paths (EDIT THESE)
# -------------------------------
MODEL_PATH = r"D:\Downloads\fastener_detection_run1 (1)\weights\best.pt"
IMAGE_PATH = r"C:\Users\HP\OneDrive\Desktop\screw\object_detection_dataset\test\images\screws_0430.jpg"

# -------------------------------
# Load model
# -------------------------------
model = YOLO(MODEL_PATH)

# -------------------------------
# Run inference
# -------------------------------
results = model(IMAGE_PATH, conf=0.25)

# -------------------------------
# Get annotated image
# -------------------------------
annotated_img = results[0].plot()   # draws boxes, labels, confidence

# -------------------------------
# Show image in VS Code window
# -------------------------------
cv2.imshow("YOLOv8 Inference Result", annotated_img)
cv2.waitKey(0)
cv2.destroyAllWindows()