如何计算边界框坐标?

时间:2020-11-08 08:22:12

标签: python cnn yolo bounding-box

我已经创建了训练有素的yolov4模型,并且我也尝试对其进行测试。 我原来的图片大小是-宽1920和高1080。

为了训练,我将其减小为416 * 416。经过测试后,我得到了不错的结果,但是我无法理解输出值:

(left_x:506 top_y:-376宽度:2076高度:1179)

(坐标如何为负数或大于图像的大小?)

我确定它后面有一个公式,但我找不到它。 我在代码(darknet.py)中进行搜索,然后bbox2points(bbox)函数返回了错误的结果。

我想念什么?

在此示例中,您能帮我找到边界框的坐标吗?

代码-darknet.py:

x, y, w, h = bbox
xmin = int(round(x - (w / 2)))
xmax = int(round(x + (w / 2)))
ymin = int(round(y - (h / 2)))
ymax = int(round(y + (h / 2)))
return xmin, xmax, ymin, ymax

x,y,w,h与其输出相同(left_x,top_y,宽度,高度) 码: https://github.com/AlexeyAB/darknet/blob/master/darknet.py

1 个答案:

答案 0 :(得分:0)

这是我转换darknet_video.py返回的边界框以在opencv中使用它的方式。


    def __transform_boxes(boxes, image):
        image_height, image_width, image_channels = image.shape
        top_coordinates_x = int((boxes[0] - (boxes[2]) / 2) * (image_width / 416))
        top_coordinates_y = int((boxes[1] - (boxes[3]) / 2) * (image_height / 416))
        bottom_coordinates_x = int((boxes[0] + (boxes[2]) / 2) * (image_width / 416))
        bottom_coordinates_y = int((boxes[1] + (boxes[3]) / 2) * (image_height / 416))
        return bottom_coordinates_x, bottom_coordinates_y, top_coordinates_x, top_coordinates_y