Home > front end >  convert bounding box coordinates to x,y pairs
convert bounding box coordinates to x,y pairs

Time:08-13

I have a bounding box coordinates in this format [x, y, width, height],

how can I get all the x and y pairs from it?

the result is going to be in this format [(x1,y1),(x2,y2),...,(xn,yn)]

thanks in advance!

CodePudding user response:

I'm not sure if I understand your data description correctly, but here's an example that might fit:

data = [
    [1, 2, 100, 100],
    [3, 4, 100, 100],
    [5, 6, 200, 200],
]

result = [tuple(x[:2]) for x in data]

Result:

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

CodePudding user response:

Is this what you mean?

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)
  • Related