File size: 467 Bytes
04b4385
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
import cv2
import numpy as np

def draw_boxes(frame, detections, class_names):
    for x1, y1, x2, y2, conf, cls_id in detections:
        label = class_names[int(cls_id)]
        color = (0, 255, 0) if label == 'ball' else (255, 0, 0)
        cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)), color, 2)
        cv2.putText(frame, f"{label} {conf:.2f}", (int(x1), int(y1) - 5),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2)
    return frame