Real-time object detection and image classification system
from ultralytics import YOLO
import cv2
class ObjectDetector:
def __init__(self, model_path: str = "yolov8n.pt"):
self.model = YOLO(model_path)
def detect(self, image_path: str):
results = self.model(image_path)
detections = []
for result in results:
for box in result.boxes:
detections.append({
"class": result.names[int(box.cls)],
"confidence": float(box.conf),
"bbox": box.xyxy.tolist()
})
return detections