将边界框注释从[xmin, ymin, width, height]转换为YOLOv7



我正在努力翻译坐标从[xmin, ymin,宽度,高度]到YOLOv7表示,有人能帮助我吗?

例如我的图像是width = 9477px,hight = 23354px[xmin, ymin, width, height]的注释为:

[2009 21947 207 251]

我想知道如何将其转换为YoloV7坐标。

得到了答案:

def convert_bbox_coco2yolo(img_width, img_height, bbox):
"""
Convert bounding box from COCO  format to YOLO format
Parameters
----------
img_width : int
width of image
img_height : int
height of image
bbox : list[int]
bounding box annotation in COCO format: 
[top left x position, top left y position, width, height]
Returns
-------
list[float]
bounding box annotation in YOLO format: 
[x_center_rel, y_center_rel, width_rel, height_rel]
"""

# YOLO bounding box format: [x_center, y_center, width, height]
# (float values relative to width and height of image)
x_tl, y_tl, w, h = bbox
dw = 1.0 / img_width
dh = 1.0 / img_height
x_center = x_tl + w / 2.0
y_center = y_tl + h / 2.0
x = x_center * dw
y = y_center * dh
w = w * dw
h = h * dh
return [x, y, w, h]

相关内容

  • 没有找到相关文章

最新更新