如何理解Open Images Dataset的边界框注释?

问题描述 投票:0回答:1

所以我通过TensorFlow数据集(https://www.tensorflow.org/datasets)下载了Open Images Dataset。我可以很好地查看图像和注释,但我无法理解它们用于对象边界框的奇怪格式。

例如:我有一个图像显示大象的宽度为682,高度为1024.大象的边界框坐标为:[0.03875,0.188732,0.9554375,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
python matplotlib coordinates rectangles bounding-box
1个回答
1
投票

我自己找到了解决方案:事实证明,当使用TensorFlow Datasets API中的Open Images时,边界框的坐标顺序与数据集网站上记录的顺序不同。 在那里,他们描述了每个框的四个值的顺序如下: xMin,xMax,yMin,yMax。 但是,TF Datasets API的顺序是yMin,xMin,yMax,xMax。我通过比较单个图像中的图像ID和网站上的annotations.csv文件找到了这一点。获得框的绝对值的唯一步骤是将x值与图像的宽度相乘,将y值与其高度相乘。

© www.soinside.com 2019 - 2024. All rights reserved.