Search code examples
pythonpytorchyoloyolov5

How to convert Bounding Box coordinates to Yolo Coordinates with Python?


I need to convert the coordinates. I have this format <left> <top> <width> <height> And I need x_center y_center width height in this format. How can I do it?


Solution

  • The center is just the middle of your bounding box. So just add half of the bounding box width or height to yout top-left coordinate. Width and height remain unchanged

    x_center = left + width / 2
    y_center = top + height / 2