convert boundingPoly to yolo format
Yolov5 doesn't support segmentation labels and I need to convert it into the correct format.
How would you convert this to yolo format?
        &quot;boundingPoly&quot;: {
            &quot;normalizedVertices&quot;: [{
                &quot;x&quot;: 0.026169369
            }, {
                &quot;x&quot;: 0.99525446
            }, {
                &quot;x&quot;: 0.99525446,
                &quot;y&quot;: 0.688811
            }, {
                &quot;x&quot;: 0.026169369,
                &quot;y&quot;: 0.688811
            }]
        }

The yolo format looks like this
0 0.588196 0.474138 0.823607 0.441645
&lt;object-class&gt; &lt;x&gt; &lt;y&gt; &lt;width&gt; &lt;height&gt;


After our back and forth in the comments I have enough info to answer your question. This is output from the Google Vision API. The normalizedVertices are similar to the YOLO format, because they  are &quot;normalized&quot; meaning the coordinates are scaled between 0 and 1 as opposed to being pixels from 1 to n. Still, you need to do some transformation to put into the YOLO format. In the YOLO format, the X and Y values in the 2nd and 3rd columns refer to the center of the bounding box, as opposed to one of the corners.
Here is a code snipped that will sample at https://ghostbin.com/hOoaz/raw into the follow string in YOLO format '0 0.5080664305 0.5624289849999999 0.9786587390000001 0.56914843'
#Sample annotation output 
json_annotation = &quot;&quot;&quot;
      [
        {
          &quot;mid&quot;: &quot;/m/01bjv&quot;,
          &quot;name&quot;: &quot;Bus&quot;,
          &quot;score&quot;: 0.9459266,
          &quot;boundingPoly&quot;: {
            &quot;normalizedVertices&quot;: [
              {
                &quot;x&quot;: 0.018737061,
                &quot;y&quot;: 0.27785477
              },
              {
                &quot;x&quot;: 0.9973958,
                &quot;y&quot;: 0.27785477
              },
              {
                &quot;x&quot;: 0.9973958,
                &quot;y&quot;: 0.8470032
              },
              {
                &quot;x&quot;: 0.018737061,
                &quot;y&quot;: 0.8470032
              }
            ]
          }
        }
      ]
&quot;&quot;&quot;

import json
json_object = json.loads(json_annotation, strict=False)

#Map all class names to class id
class_dict = {&quot;Bus&quot;: 0}
#Get class id for this record
class_id = class_dict[json_object[0][&quot;name&quot;]]

#Get the max and min values from segmented polygon points 
normalizedVertices = json_object[0][&quot;boundingPoly&quot;][&quot;normalizedVertices&quot;]
max_x = max([v['x'] for v in normalizedVertices])
max_y = max([v['y'] for v in normalizedVertices])
min_x = min([v['x'] for v in normalizedVertices])
min_y = min([v['y'] for v in normalizedVertices])

width = max_x - min_x
height = max_y - min_y 
center_x = min_x + (width/2)
center_y = min_y + (height/2)

yolo_row = str(f&quot;{class_id} {center_x} {center_y} {width} {height}&quot;)
print(yolo_row)

If you are trying to train a YOLO model there are a few more steps you will need to do: You need to setup the images and annotations in a particular folder structure. But this should help you convert your annotations.
