Spaces:
Sleeping
Sleeping
File size: 682 Bytes
03efa53 eb82720 03efa53 |
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 |
from ultralytics import YOLO
import cv2
import sys
# Check for command-line argument
if len(sys.argv) < 2:
print("Usage: python detect_image.py <image_path>")
sys.exit(1)
image_path = sys.argv[1]
# Load trained model
model = YOLO("best50.pt")
# Read image
frame = cv2.imread(image_path)
if frame is None:
print(f"Error: Could not read image at {image_path}")
sys.exit(1)
# Run detection with conf and iou threshold
results = model(frame, conf=0.5, iou=0.4, imgsz=640, augment=False)
# Plot and save results
annotated_img = results[0].plot()
cv2.imwrite("output.jpg", annotated_img)
cv2.imshow("Detection", annotated_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
|