繁体   English   中英

如何计算边界框坐标?

[英]How to calculate bounding box coordinates?

我已经创建了一个经过训练的 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, width, height) 代码: https : //github.com/AlexeyAB/darknet/blob/master/darknet.py

这就是我如何转换由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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM