-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataVisualizer.py
More file actions
51 lines (41 loc) · 1.51 KB
/
Copy pathDataVisualizer.py
File metadata and controls
51 lines (41 loc) · 1.51 KB
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
41
42
43
44
45
46
47
48
49
50
51
import cv2 as cv
class DataVisualizer:
HEADER = 1
SUBTITLE = 2
TEXT = 3
def __init__(self, font, width=300, height=300, x=0, y=0, marginLeft=20, colWidth = 120):
self.font = font
self.marginLeft = marginLeft
self.x = x
self.y = y
self.yPos = y
self.data = []
self.width = width
self.height = height
self.colWidth = colWidth
def add(self, text, size, r=255, g=255, b=255):
self.data.append({"text": text, "size": size, "red": r, "green": g, "blue": b})
def display(self, frame):
cv.rectangle(frame, (self.x, self.y), (self.width + self.x, self.height + self.y), (20, 20, 20), -1)
for info in self.data:
size = 0
if info["size"] == self.HEADER:
self.yPos += 50
size = 1.5
if info["size"] == self.SUBTITLE:
self.yPos += 40
size = 1
if info["size"] == self.TEXT:
self.yPos += 20
size = 0.5
posx = self.marginLeft
for col in info["text"]:
cv.putText(frame, col, (posx, self.yPos), self.font, size,
(info["blue"], info["green"], info["red"]), int(size + 0.5), cv.LINE_AA)
posx += self.colWidth
if info["size"] == self.HEADER:
self.yPos += 10
if info["size"] == self.SUBTITLE:
self.yPos += 10
self.data = []
self.yPos = self.y