Spaces:
Runtime error
Runtime error
adding black background to messages
Browse files
app.py
CHANGED
@@ -55,20 +55,28 @@ def add_border(frame, color = (255, 0, 0), thickness = 2):
|
|
55 |
|
56 |
return bordered_image
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
61 |
for i, line in enumerate(text_list):
|
62 |
y = y0 + i * dy
|
63 |
-
if 'Shark' in line or 'Human' in line
|
64 |
-
|
65 |
-
cv2.
|
|
|
|
|
66 |
else:
|
67 |
-
|
68 |
-
cv2.
|
|
|
|
|
69 |
|
70 |
return image
|
71 |
|
|
|
72 |
def overlay_logo(frame,logo, position=(10, 10)):
|
73 |
"""
|
74 |
Overlay a transparent logo (with alpha channel) on a frame.
|
|
|
55 |
|
56 |
return bordered_image
|
57 |
|
58 |
+
|
59 |
+
|
60 |
+
def overlay_text_on_image(image, text_list, font=cv2.FONT_HERSHEY_SIMPLEX, font_size=0.5, font_thickness=1, margin=10, color=(255, 255, 255), box_color=(0,0,0)):
|
61 |
+
relative = min(image.shape[0], image.shape[1])
|
62 |
+
y0, dy = margin, int(relative*0.1) # start y position and line gap
|
63 |
+
|
64 |
for i, line in enumerate(text_list):
|
65 |
y = y0 + i * dy
|
66 |
+
if 'Shark' in line or 'Human' in line:
|
67 |
+
current_font_size = font_size * 1.5
|
68 |
+
text_width, text_height = cv2.getTextSize(line, font, current_font_size, font_thickness)[0]
|
69 |
+
cv2.rectangle(image, (image.shape[1] - text_width - margin - 5, y - text_height), (image.shape[1] - margin + 5, y + 5), box_color, -1)
|
70 |
+
cv2.putText(image, line, (image.shape[1] - text_width - margin, y), font, current_font_size, color, font_thickness, lineType=cv2.LINE_AA)
|
71 |
else:
|
72 |
+
current_font_size = font_size
|
73 |
+
text_width, text_height = cv2.getTextSize(line, font, current_font_size, font_thickness)[0]
|
74 |
+
cv2.rectangle(image, (image.shape[1] - text_width - margin - 5, y - text_height), (image.shape[1] - margin + 5, y + 5), box_color, -1)
|
75 |
+
cv2.putText(image, line, (image.shape[1] - text_width - margin, y), font, current_font_size, color, font_thickness, lineType=cv2.LINE_AA)
|
76 |
|
77 |
return image
|
78 |
|
79 |
+
|
80 |
def overlay_logo(frame,logo, position=(10, 10)):
|
81 |
"""
|
82 |
Overlay a transparent logo (with alpha channel) on a frame.
|