将边界框坐标转换为x,y对



我有一个边界框坐标,格式为[x,y,width,height],

我怎样才能从中得到所有的x和y对?

结果将是这种格式[(x1,y1(,(x2,y2(,…,(xn,yn(]

提前感谢!

我不确定我是否正确理解您的数据描述,但这里有一个可能适合的例子:

data = [
[1, 2, 100, 100],
[3, 4, 100, 100],
[5, 6, 200, 200],
]
result = [tuple(x[:2]) for x in data]

结果:

[(1, 2), (3, 4), (5, 6)]

根据我对您问题的理解,以下是答案:

data = [1, 2, 100, 100]    ## x=1, y=2, width=100, height=100
coordinates = [[x, y], [x + width, y], [x + width, y + height], [x, y + height]]

边界框的所有4个坐标的结果:

[[1, 2], [101, 2], [101, 102], [1, 102]]

这就是你的意思吗?

data = [
[1, 2, 100, 100],
[3, 4, 100, 100],
[5, 6, 200, 200],
]
answer = []
for n in data:
answer.append(n[0:2])
print(answer)

最新更新