![](/img/trans.png)
[英]How to get class and bounding box coordinates from YOLOv5 predictions?
[英]Get bounding box coordinates (xywh) from quad coordinates and normalize them
我有这些照片中物体的照片和坐标。
例如:
{
"shape_attributes": {
"name": "polygon",
"all_points_x": [613, 2007, 1769, 581],
"all_points_y": [1767, 1674, 2260, 2395]
},
"region_attributes": {"field_name": "doc_quad"}
}
我需要将它们转换为 4 点:
x_center y_center width height
得到一个边界框。 之后,我需要按照以下说明对它们进行标准化:
Box coordinates must be in normalized xywh format (from 0 - 1). If your boxes are in pixels, divide x_center and width by image width, and y_center and height by image height.
如何将 8 个尖角多边形坐标转换为归一化形式(4 个点)?
这个问题可能需要一些几何知识,如果你觉得这个问题太简单,你可以发送相关文章的链接。 问题是我不知道如何向 Google 提问以找到答案,因为How to convert 8 point polygon coordinates into 4 point rectangle coordinates
并没有给我想要的结果(我发现的大多数文章都假设我不知道不知道实际坐标并使用opencv
一些检测函数,但我知道实际坐标)这就是我在这里问的原因。
由于多边形不是矩形,一种方法是取一个覆盖所有点内部的边界框,或者一个被所有点覆盖的紧密矩形。 下面是第一种方法。
"all_points_x": [613, 2007, 1769, 581]
"all_points_y": [1767, 1674, 2260, 2395]
虽然图(0,0)
在左下角,图像(0,0)
点从左上角开始,但想法是相同的。 我的图形参考中只有顶部和底部的水平线被翻转为图像。
图表在这里, https://www.desmos.com/calculator/bzhbyrgz3o
取all_points_x
的最大值得到最右边的垂直线,取all_points_x
最小值得到最左边的垂直线。 类似地取all_points_y
最大值和最小值来获得顶部和底部的水平线。
p2 = max([613,2007,1769,581]) = 2007
p1 = min([613,2007,1769,581]) = 581
q2 = max([1767,1674,2260,2395]) = 2395
q1 = min([1767,1674,2260,2395]) = 1674
通过以下方式获取中心点(cx,cy)
,
cx = (p1 + p2) / 2 = 1294
cy = (q1 + q2) / 2 = 2034.5
获取宽度,高度, (w,h)
,
w = p2 - p1 = 1426
h = q2 - q1 = 721
现在,如果图像是(im_w, im_h)
那么标准化格式将是,
cx_new = cx / im_w
w_new = w / im_w
cy_new = cy / im_h
h_new = h / im_h
所以这4点是,
cx_new cy_new w_new h_new
YOLO 使用这种格式x_center y_center width height
。 这个链接应该会有所帮助。
可以从
--> min(x),min(y) max(x),max(y)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.