[英]How to convert Bounding Box coordinates to COCO format?
I need to convert the coordinates.我需要转换坐标。 I have this format: Horizontal and Vertical coordinates of the top left and lower right of the element ((x1, y1) and (x2, y2)).
我有这种格式:元素左上角和右下角的水平和垂直坐标((x1,y1)和(x2,y2))。 And I need x_center y_center width height in this format.
我需要这种格式的 x_center y_center 宽度高度。 How can I do it?
我该怎么做?
The center and the size are simply中心和大小只是
x_center = 0.5 * (x1 + x2)
y_center = 0.5 * (y1 + y2)
width = np.abs(x2 - x1)
height = np.abs(y2 - y1)
Note that by using np.abs
when computing the width and height we do need to assume anything on the "order" of the first and second corners.请注意,通过在计算宽度和高度时使用
np.abs
我们确实需要假设第一个和第二个角的“顺序”。
If you further want to normalize the center and size by the image size (img_w, img_h)
:如果您还想通过图像大小
(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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.