【发布时间】:2021-09-27 18:13:10
【问题描述】:
我需要转换坐标。我有这种格式:水平和 元素左上角和右下角的垂直坐标((x1,y1)和(x2,y2))。我需要这种格式的 x_center y_center 宽度高度。我该怎么做?
【问题讨论】:
标签: python computer-vision pytorch object-detection yolo
我需要转换坐标。我有这种格式:水平和 元素左上角和右下角的垂直坐标((x1,y1)和(x2,y2))。我需要这种格式的 x_center y_center 宽度高度。我该怎么做?
【问题讨论】:
标签: python computer-vision pytorch object-detection yolo
中心和大小很简单
x_center = 0.5 * (x1 + x2)
y_center = 0.5 * (y1 + y2)
width = np.abs(x2 - x1)
height = np.abs(y2 - y1)
请注意,在计算宽度和高度时使用np.abs,我们确实需要假设第一个和第二个角的“顺序”。
如果你还想通过图片大小(img_w, img_h)来归一化中心和大小:
n_x_center = x_center / img_w
n_y_center = y_center / img_h
n_width = width / img_w
n_height = height / img_h
【讨论】: