File size: 906 Bytes
98a3af2
 
 
 
 
9482f97
98a3af2
 
9482f97
 
98a3af2
 
9482f97
 
 
 
 
 
 
 
 
 
98a3af2
 
9482f97
98a3af2
 
 
9482f97
 
 
 
 
 
 
 
 
 
98a3af2
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
32
33
34
35
36
37
38
39
40
import cv2
import time

COLOR = (0, 255, 0)


def draw_boxes(img, detections, show_scores=True):
    out = img.copy()
    for cls, conf, (x1, y1, x2, y2) in detections:
        cv2.rectangle(out, (int(x1), int(y1)), (int(x2), int(y2)), COLOR, 2)
        if show_scores:
            label = f"{cls} {conf:.2f}"
            cv2.putText(
                out,
                label,
                (int(x1), int(y1) - 6),
                cv2.FONT_HERSHEY_SIMPLEX,
                0.6,
                COLOR,
                2,
                cv2.LINE_AA,
            )
    return out


def draw_hud(img, fps=0.0, model="yolov8n.pt"):
    out = img.copy()
    hud = f"{model} | {fps:.1f} FPS | {time.strftime('%H:%M:%S')}"
    cv2.putText(
        out,
        hud,
        (12, 28),
        cv2.FONT_HERSHEY_SIMPLEX,
        0.7,
        (255, 255, 255),
        2,
        cv2.LINE_AA,
    )
    return out