Closed loomcode closed 1 year ago
Taking an example from Detectron2, I added a polygon friendly version of your "convert_to_coco" function by making some minor changes to the bounding box loop:
for bbox in bboxes:
category_name = bbox['polygonlabels'][0]
if category_name not in category_name_to_id:
category_id = len(categories)
category_name_to_id[category_name] = category_id
categories.append({
'id': category_id,
'name': category_name
})
category_id = category_name_to_id[category_name]
annotation_id = len(annotations)
**poly = [(x + 0.5, y + 0.5) for x, y in bbox['points']]
pxpy = np.array(poly)
poly = [p for x in poly for p in x]
annotations.append({
'id': annotation_id,
'image_id': image_id,
'category_id': category_id,
'segmentation': [poly],
'bbox': [np.min(pxpy[:,0]), np.min(pxpy[:,1]), np.max(pxpy[:,0]), np.max(pxpy[:,1])],
'ignore': 0,
'iscrowd': 0
})**
Note, that I changed the bbox boundaries to absolute coords and imported numpy. It runs but I still need to check if the output works with a model.
@loomcode ,
This functionality has been added since label-studio>=0.7.5
. Can you try it out and close an issue if everything is OK ?
I'd like to convert a list of JSONs I generated with the polygon tool in label studio to COCO format but it doesn't look like the code handles this use case.