【问题标题】:Adjust bounding box in yolo format when resizing image调整图像大小时以yolo格式调整边界框
【发布时间】:2020-11-26 11:15:10
【问题描述】:

我正在尝试调整图像大小,但调整图像大小还需要我更改边界框值。 有没有这个是yolo格式x y width height

当我调整特定宽度和高度的图像大小时,在将图像调整为 python 中的 temp_width 和 temp_height 后,将格式 x y 宽度高度的归一化绑定框值转换为新值的逻辑是什么

【问题讨论】:

  • scaling_factor_width = newImageSizeWidth/oldImageSizeWidth 现在只需使用该缩放因子缩放边界框的 x 坐标和边界框的宽度值。边界框的 scale_factor_height 和 height 和 y 坐标相同。如果要使用子图像(裁剪),则必须从边界框 x/y 位置减去子图像位置的新 x/y 坐标。

标签: python opencv yolo


【解决方案1】:

YOLO 格式确实是一个 bbox(也称为边界框)坐标/数据归一化。

Here,有明确的解释如何获取这些数据(以及 Pascal VOC)。
下面,您将找到获取这些 Yolo 格式数据的代码。
然后您就会明白,只要您使用缩放的图像,就没有什么可以改变的。

实际上,bbox 的标准化 x_center、y_center、box_width 和 box_height 坐标将根据图像进行相应缩放。

但是,如果您裁剪它们,则需要检索 bbox 的 [x_topleft, y_topleft, box_width, box_height] 坐标,并使用该crop_image 的大小对其进行归一化。

假设您有一个“bbox”:

bbox = np.array([x_topleft, y_topleft, box_width, box_height])
       
b_width = bbox[2,]
b_height = bbox[3,]
x_max = bbox[0,] + b_width
y_max = bbox[1,] + b_height

bbox[0,] = ((x_max + bbox[0,]) / 2)  / width
bbox[1,] = ((y_max + bbox[1,]) / 2)  / height
bbox[2,] = bbox[2,] / width
bbox[3,] = bbox[3,] / height
        
bobox = bbox[0,], bbox[1,], bbox[2,], bbox[3,] # normalized x_center, y_center, box_width and box_height

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-03
    • 1970-01-01
    • 2023-01-27
    • 1970-01-01
    • 2015-01-16
    • 2011-07-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多