/ AI_Traffic_Monitoring_System / detector.py
detector.py
1 from ultralytics import YOLO 2 from config import TARGET_CLASSES, CONFIDENCE_THRESHOLD 3 4 model = YOLO("yolov8n.pt") 5 6 def detect(frame): 7 results = model(frame, verbose=False)[0] 8 detections = [] 9 10 for box in results.boxes: 11 cls_id = int(box.cls[0]) 12 label = model.names[cls_id] 13 confidence = float(box.conf[0]) 14 15 if label in TARGET_CLASSES and confidence > CONFIDENCE_THRESHOLD: 16 x1, y1, x2, y2 = map(int, box.xyxy[0]) 17 detections.append((label, confidence, x1, y1, x2, y2)) 18 19 return detections