Search code examples
pythoncomputer-visionobject-detectionyolobounding-box

Changing Bounding Box Label Format


I was looking for an online service that allow me to annotate images with bounding boxes, I found labelbox, but there bounding box label format is different than the format that I need which is yolo.

This is there format: "bbox": { "top": 186, "left": 192, "height": 300, "width": 519 }.

The format that i need is x_center y_center width height, also the values needs to be between 0 and 1


Solution

  • bbox = {"top": 186, "left": 192,  "height": 300, "width": 519}
    
    y1 = bbox["top"]
    x1 = bbox["left"]
    height = bbox["height"]
    width = bbox["width"]
    
    x2 = x1+width
    y2 = y1+height
    
    x_center = round((x1+x2)/2)
    y_center = round((y1+y2)/2)
    
    bbox_list = [x_center, y_center, width, height]