Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mask = label == label_i
if 1.0 * mask.sum() / mask.size < thresh_suppress:
continue
y, x = np.array(_center_of_mass(mask), dtype=int)
if label[y, x] != label_i:
Y, X = np.where(mask)
point_index = np.random.randint(0, len(Y))
y, x = Y[point_index], X[point_index]
text = label_names[label_i]
height, width = draw_module.text_size(
text, size=font_size, font_path=font_path
)
color = color_module.get_fg_color(res[y, x])
res = draw_module.text(
res,
yx=(y - height // 2, x - width // 2),
text=text,
color=color,
size=font_size,
font_path=font_path,
)
elif loc in ["rb", "lt"]:
text_sizes = np.array(
[
draw_module.text_size(
label_names[l], font_size, font_path=font_path
)
for l in unique_labels
]
)
def test_text():
img = np.full((100, 100, 3), 255, dtype=np.uint8)
res = imgviz.draw.text(
img, yx=(0, 0), text="TEST", color=(0, 0, 0), size=30
)
assert res.shape == img.shape
assert res.dtype == img.dtype
assert not np.allclose(img, res)
)
alpha = 0.5
y1, x1 = aabb1.round().astype(int)
y2, x2 = aabb2.round().astype(int)
res[y1:y2, x1:x2] = (
alpha * res[y1:y2, x1:x2] + alpha * legend[y1:y2, x1:x2]
)
for i, l in enumerate(unique_labels):
box_aabb1 = aabb1 + (i * text_height + 5, 5)
box_aabb2 = box_aabb1 + (text_height - 10, text_height - 10)
res = draw_module.rectangle(
res, aabb1=box_aabb1, aabb2=box_aabb2, fill=colormap[l]
)
res = draw_module.text(
res,
yx=aabb1 + (i * text_height, 10 + (text_height - 10)),
text=label_names[l],
size=font_size,
font_path=font_path,
)
else:
raise ValueError("unsupported loc: {}".format(loc))
return res