【发布时间】:2019-09-13 21:35:56
【问题描述】:
所以我通过 TensorFlow Datasets (https://www.tensorflow.org/datasets) 下载了 Open Images Dataset。我可以很好地查看图像和注释,但我无法理解它们用于对象边界框的奇怪格式。
例如:我有一张图片显示一头大象,宽度为 682,高度为 1024。大象的边界框坐标为:[0.03875 , 0.188732, 0.954375, 0.979343]。根据文档,这 4 个数字代表 xMin、xMax、yMin、yMax。
我如何显示这个奇怪的小矩形,比如说 matplotlib?
我已经尝试将坐标分别与宽度和高度相乘,但生成的矩形没有任何意义。我还切换了 x_1 和 x_2 等的值,但这也不起作用。
这是我的代码:
for e in train_data:
np_img = e["image"]
height = np.shape(np_img)[0]
width = np.shape(np_img)[1]
fig, ax = plt.subplots(1)
ax.imshow(np_img)
for bbox in e["bobjects"]["bbox"]:
x_1 = bbox[0]
x_2 = bbox[1]
y_1 = bbox[2]
y_2 = bbox[3]
rect = patches.Rectangle((x_1 * width, y_2 * height), (x_2 * width - x_1 * width), (y_1 * height - y_2 * height), linewidth=1, edgecolor='r', facecolor='none')
ax.add_patch(rect)
plt.show()
# Only one iteration for testing
break
【问题讨论】:
-
好像和半小时前的this question一样。也许您可以与该问题的提问者合作,共同提出一个带有minimal reproducible example 的问题,并允许了解实际问题。
标签: python matplotlib coordinates rectangles bounding-box