import cv2 as cv import numpy as np from typing import Tuple class DrawingUtils: @staticmethod def draw_text_with_bg( frame: np.ndarray, text: str, pos: Tuple[int, int], font=cv.FONT_HERSHEY_SIMPLEX, font_scale: float = 0.6, thickness: int = 2, bg_color=(255, 255, 255), text_color=(0, 0, 0) ): (w, h), baseline = cv.getTextSize(text, font, font_scale, thickness) x, y = pos cv.rectangle( frame, (x, y - h - baseline), (x + w, y + baseline), bg_color, cv.FILLED ) cv.putText( frame, text, (x, y), font, font_scale, text_color, thickness, cv.LINE_AA )