【问题标题】:How to add text to an image segment如何将文本添加到图像段
【发布时间】:2019-05-13 09:35:42
【问题描述】:

我有以下 Python 代码,它在检测到的片段周围添加了一个边界框

%matplotlib qt
fig, ax = plt.subplots(figsize=(10, 6))
ax.imshow(image_label_overlay)
for region in regions:
 # take regions with large enough areas
 if region.area >= 100:
    # draw rectangle around segmented coins
    minr, minc, maxr, maxc = region.bbox
    rect = mpatches.Rectangle((minc, minr), maxc - minc, maxr - minr,
                              fill=False, edgecolor='red', linewidth=2)
    ax.add_patch(rect)


 ax.set_axis_off()

 plt.tight_layout()
 plt.show()

我不想绘制边界框,而是想对段进行编号。即我想在每个段的中心添加一个数字。我该怎么做?

【问题讨论】:

标签: python image image-processing label image-segmentation


【解决方案1】:
plt.text(x, y, s, bbox=dict(fill=False, edgecolor='red', linewidth=2))

x 是 x 轴的坐标,y 是 y 轴的坐标。 s 是您要写入情节的字符串。

bbox 让你在它周围有一个文本和一个矩形。 bbox 需要具有 Rectangle 属性 (https://matplotlib.org/api/_as_gen/matplotlib.patches.Rectangle.html#matplotlib.patches.Rectangle) 的 dict,您已经在代码中使用了该属性。

【讨论】:

    猜你喜欢
    • 2019-04-12
    • 1970-01-01
    • 2018-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-14
    • 2021-08-17
    相关资源
    最近更新 更多