Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return res
if loc == "centroid":
for label_i in unique_labels:
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
def test_rectangle():
img = np.full((100, 100, 3), 255, dtype=np.uint8)
res = imgviz.draw.rectangle(img, (0, 0), (50, 50), outline=(0, 0, 0))
assert res.shape == img.shape
assert res.dtype == img.dtype
def draw():
img = imgviz.data.lena()
H, W = img.shape[:2]
viz = img
y1, x1 = 200, 180
y2, x2 = 400, 380
viz = imgviz.draw.rectangle(
viz, (y1, x1), (y2, x2), outline=(255, 255, 255), width=5
)
viz = imgviz.draw.text_in_rectangle(
viz,
loc="lt",
text="face",
size=30,
background=(255, 255, 255),
aabb1=(y1, x1),
aabb2=(y2, x2),
)
# eye, eye, nose, mouse, mouse
xys = [(265, 265), (330, 265), (315, 320), (270, 350), (320, 350)]
colors = imgviz.label_colormap(value=255)[1:]
shapes = ["star", "star", "rectangle", "circle", "triangle"]
pass
for instance_id in range(n_instance):
bbox = bboxes[instance_id]
label = labels[instance_id]
caption = captions[instance_id]
color_cls = colormap[label % len(colormap)]
y1, x1, y2, x2 = bbox
if (y2 - y1) * (x2 - x1) == 0:
continue
aabb1 = np.array([y1, x1], dtype=int)
aabb2 = np.array([y2, x2], dtype=int)
dst = draw_module.rectangle(
dst, aabb1, aabb2, outline=color_cls, width=line_width,
)
if caption is not None:
for loc in ["lt+", "lt"]:
y1, x1, y2, x2 = draw_module.text_in_rectangle_aabb(
src=dst,
loc=loc,
text=caption,
size=font_size,
aabb1=aabb1,
aabb2=aabb2,
font_path=font_path,
)
if (
y1 >= 0