Spaces:
Build error
Build error
File size: 833 Bytes
f62bf7a | 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 | 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
)
|