![](/img/trans.png)
[英]How to convert 2D bounding box pixel coordinates (x, y, w, h) into relative coordinates (Yolo format)?
[英]convert bounding box coordinates to x,y pairs
我有一個這種格式的邊界框坐標 [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],
[3, 4, 100, 100],
[5, 6, 200, 200],
]
answer = []
for n in data:
answer.append(n[0:2])
print(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]]
邊界框的所有 4 個坐標的結果:
[[1, 2], [101, 2], [101, 102], [1, 102]]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.