我有以下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()
我不想绘制边界框,而是要对段进行编号。即我想在每个段的中心添加一个数字。我怎样才能做到这一点?
plt.text(x, y, s, bbox=dict(fill=False, edgecolor='red', linewidth=2))
与x
为您的x轴的coodinate和y
您的y轴的坐标。s
是要写入情节的字符串。
bbox让我们同时拥有一个文本和一个矩形。bbox
需要具有Rectangle属性(https://matplotlib.org/api/_as_gen/matplotlib.patches.Rectangle.html#matplotlib.patches.Rectangle)的字典,您已在代码中使用了该属性。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句