喂!我正在通过一个在线平台对图像数据进行注释,它正在生成如下输出坐标:{“bbox":{"top":634,”左侧“:523,”身高“:103,”宽度“:145},但是,我想使用这个注释来训练Yolo,所以,我必须以yolo格式转换它:4 0.838021 0.605556 0.177083 0.237037
在这方面,我需要关于如何转换它的帮助。
发布于 2020-11-01 16:45:34
在这里,对于需要传递(w,h)和需要传递(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)
或者,您可以使用下面的
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。让我们看一个例子:
What does the coordinate output of yolo algorithm represent?
发布于 2020-12-08 22:02:11
将bbox字典转换为具有相对坐标的列表
如果要将包含键top
、left
、widht
、height
的python字典转换为格式为x1
、y1
、x2
、y2
的列表
如果x1
、y1
是包围框的top left corner
的相对坐标,而x2
则是边框的bottom right corner
的相对坐标,则可以使用以下函数:
def bbox_dict_to_list(bbox_dict, image_size):
h = bbox_dict.get('height')
l = bbox_dict.get('left')
t = bbox_dict.get('top')
w = bbox_dict.get('width')
img_w, img_h = image_size
x1 = l/img_w
y1 = t/img_h
x2 = (l+w)/img_w
y2 = (t+h)/img_h
return [x1, y1, x2, y2]
您必须将bbox字典作为参数传递,图像大小以元组-> (image_width,image_height)的形式传递。
示例
bbox = {"top":634,"left":523,"height":103,"width":145}
bbox_dict_to_list(bbox, (1280, 720))
>> [0.40859375, 0.8805555555, 0.521875, 1.02361111111]
您可以根据您的需要更改退货顺序。
https://stackoverflow.com/questions/64634300
复制相似问题