Coverage for skcvideo/utils.py: 0%
19 statements
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-02 14:10 +0200
« prev ^ index » next coverage.py v7.6.1, created at 2024-10-02 14:10 +0200
1import cv2
3from skcvideo.colors import WHITE
5DEFAULT_FONT = cv2.FONT_HERSHEY_SIMPLEX
8def put_text(
9 img,
10 text,
11 org,
12 fontFace=DEFAULT_FONT,
13 fontScale=1.0,
14 color=WHITE,
15 thickness=1,
16 lineType=cv2.LINE_AA,
17 align_x="center",
18 align_y="center",
19):
20 x, y = org
21 (w, h), _ = cv2.getTextSize(text, fontFace, fontScale, thickness)
23 if align_x == "left":
24 org_x = x
25 elif align_x == "center":
26 org_x = x - w // 2
27 elif align_x == "right":
28 org_x = x - w
30 if align_y == "bottom":
31 org_y = y
32 elif align_y == "center":
33 org_y = y + h // 2
34 elif align_y == "top":
35 org_y = y + h
37 cv2.putText(
38 img=img,
39 text=text,
40 org=(org_x, org_y),
41 fontFace=fontFace,
42 fontScale=fontScale,
43 color=color,
44 thickness=thickness,
45 lineType=lineType,
46 )