如何在 Python 中将 YOLO 格式的注释转换为 x1、y1、x2、y2 坐标?

问题描述

我想知道如何将 YOLO 格式的注释(例如,center_X、center_y、宽度、高度 = 0.069824、0.123535、0.104492、0.120117)转换为 x1、y1、x2、y2 坐标?

解决方法

假设图像的左上角为 [0,0]:对于左上角,您必须执行 [x,y] = [center_X,center_Y] - 1/2 * [width,height] 。对于右下角 [x,center_Y] + 1/2 * [width,height]

,

如果我没记错的话:

x1 = (center_X-width/2)*image_width
x2 = (center_X+width/2)*image_width
y1 = (center_y-height/2)*image_height
y2 = (center_y+height/2)*image_height