如何将2D边界框像素坐标(x,y,w,h)转换为相对坐标(Yolo格式)? [英] How to convert 2D bounding box pixel coordinates (x, y, w, h) into relative coordinates (Yolo format)?

查看:142
本文介绍了如何将2D边界框像素坐标(x,y,w,h)转换为相对坐标(Yolo格式)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我正在通过在线平台注释图像数据,该平台生成如下所示的输出坐标: bbox":{"top":634,"left":523,"height":103,"width":145} 但是,我想使用此注释来训练Yolo.因此,我必须将其转换为yolo格式,如下所示: 4 0.838021 0.605556 0.177083 0.237037

Hy! I am annotating image data through an online plateform which is generating output coordinates like this: bbox":{"top":634,"left":523,"height":103,"width":145} However, i want to use this annotation to train Yolo. So, I have to convert it in yolo format like this: 4 0.838021 0.605556 0.177083 0.237037

在这方面,我需要有关如何进行转换的帮助.

In this regard, i need help about how to convert it.

推荐答案

在这里,对于尺寸,您需要传递(w,h),对于框则需要传递(x,x + w,y,y + h) https://github.com/ivder/LabelMeYoloConverter/blob/master/convert.py

Here, For the size you need to pass the (w,h) and the for the box you need to pass (x,x+w, y, y+h) https://github.com/ivder/LabelMeYoloConverter/blob/master/convert.py

def convert(size, box):
    dw = 1./size[0]
    dh = 1./size[1]
    x = (box[0] + box[1])/2.0
    y = (box[2] + box[3])/2.0
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    return (x,y,w,h)

或者,您可以在下面使用

Alternatively, you can use below

def convert(x,y,w,h):
 dw = 1.0/w
 dh = 1.0/h
 x = (2*x+w)/2.0
 y = (2*y+w)/2.0
 x = x*dw
 y = y*dh
 w = w*dw
 h = h*dh
 return (x,y,w,h)

每个网格单元都预测B边界框以及C类概率.边界框预测具有5个成分:(x,y,w,h,置信度).(x,y)坐标表示相对于网格单元位置的框的中心(请记住,如果框的中心不落在网格单元内,则对此单元不负责).这些坐标被归一化为介于0和1之间.相对于图像大小,(w,h)框的尺寸也被归一化为[0,1].让我们看一个例子:

Each grid cell predicts B bounding boxes as well as C class probabilities. The bounding box prediction has 5 components: (x, y, w, h, confidence). The (x, y) coordinates represent the center of the box, relative to the grid cell location (remember that, if the center of the box does not fall inside the grid cell, than this cell is not responsible for it). These coordinates are normalized to fall between 0 and 1. The (w, h) box dimensions are also normalized to [0, 1], relative to the image size. Let’s look at an example:

yolo算法的坐标输出代表什么?

这篇关于如何将2D边界框像素坐标(x,y,w,h)转换为相对坐标(Yolo格式)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆