【问题标题】:translate bounding box anotation from [xmin, ymin, width, height] to YOLOv7将边界框注释从 [xmin, ymin, width, height] 翻译成 YOLOv7
【发布时间】:2022-12-14 06:31:38
【问题描述】:

我正在努力将坐标从 [xmin, ymin, width, height] 转换为 YOLOv7 表示,有人可以帮我吗?

例如我的图片是width = 9477pxhight = 23354px[xmin, ymin, width, height] 的注解是:

[2009 21947 207 251]

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

【问题讨论】:

    标签: yolo yolov5


    【解决方案1】:

    得到了答案:

    def convert_bbox_coco2yolo(img_width, img_height, bbox): """ 将边界框从 COCO 格式转换为 YOLO 格式

    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]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-11-20
      • 2018-08-07
      • 1970-01-01
      • 2023-03-18
      • 2019-09-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多