karim ribit
karim ribit

Reputation: 11

convert bounding box coordinates to x,y pairs

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!

Upvotes: 1

Views: 595

Answers (3)

Ashutosh Pandey
Ashutosh Pandey

Reputation: 33

As per my understanding of your question here is the answer:

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]]

Result with all 4 coordinates of the bounding box:

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

Upvotes: 1

Rithvik Kandula
Rithvik Kandula

Reputation: 43

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)

Upvotes: 0

Robert Haas
Robert Haas

Reputation: 900

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)]

Upvotes: 2

Related Questions