![](/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.