将bbox字典转换为具有相对坐标的列表
如果你想用top、left、widht、height键转换python字典
以 [x1, y1, x2, y2] 格式放入列表中
其中x1、y1是边界框top left corner的相对坐标,x2、y2是边界框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]
您可以根据需要更改退货单