HumanSignal / label-studio-converter

Tools for converting Label Studio annotations into common dataset formats
https://labelstud.io/
255 stars 132 forks source link

Bounding boxes with rotation are not properly exported #131

Closed rgaiacs closed 1 year ago

rgaiacs commented 1 year ago

I created a single rotated bounding box annotation (image from https://commons.wikimedia.org/wiki/File:Radiography_of_a_pregnant_cat.jpg) with Label Studio:

Screenshot 2022-10-13 at 13-04-50 Label Studio

and exported it COCO. When I try to visualise the bounding box, it differ from the one in Label Studio:

with-boxes

JSON

[
    {
        "id": 51406,
        "annotations": [
            {
                "id": 36030,
                "completed_by": 1,
                "result": [
                    {
                        "original_width": 1554,
                        "original_height": 2321,
                        "image_rotation": 0,
                        "value": {
                            "x": 47.87138334837448,
                            "y": 69.9849260797793,
                            "width": 11.016997871904488,
                            "height": 19.62824245339836,
                            "rotation": 296.74382057984246,
                            "rectanglelabels": [
                                "Bone"
                            ]
                        },
                        "id": "8jmhYeBOOD",
                        "from_name": "label",
                        "to_name": "image",
                        "type": "rectanglelabels",
                        "origin": "manual"
                    }
                ],
                "was_cancelled": false,
                "ground_truth": false,
                "created_at": "2022-10-13T05:04:58.401108Z",
                "updated_at": "2022-10-13T05:04:58.401155Z",
                "lead_time": 54.637,
                "prediction": {},
                "result_count": 0,
                "task": 51406,
                "parent_prediction": null,
                "parent_annotation": null
            }
        ],
        "file_upload": "39cd5e69-Radiography_of_a_pregnant_cat.jpeg",
        "drafts": [],
        "predictions": [],
        "data": {
            "image": "/data/upload/58/39cd5e69-Radiography_of_a_pregnant_cat.jpeg"
        },
        "meta": {},
        "created_at": "2022-10-13T05:04:01.311983Z",
        "updated_at": "2022-10-13T05:04:01.312017Z",
        "project": 58
    }
]

COCO

{
    "images": [
        {
            "width": 1554,
            "height": 2321,
            "id": 0,
            "file_name": "images/58/39cd5e69-Radiography_of_a_pregnant_cat.jpeg"
        }
    ],
    "categories": [
        {
            "id": 0,
            "name": "Bone"
        }
    ],
    "annotations": [
        {
            "id": 0,
            "image_id": 0,
            "category_id": 0,
            "segmentation": [],
            "bbox": [
                745,
                1614,
                171,
                455
            ],
            "ignore": 0,
            "iscrowd": 0,
            "area": 77805
        }
    ],
    "info": {
        "year": 2022,
        "version": "1.0",
        "description": "",
        "contributor": "Label Studio",
        "url": "",
        "date_created": "2022-10-13 06:15:42.968872"
    }
}

Solution

Change https://github.com/heartexlabs/label-studio-converter/blob/04124cd941feb633eac2fba01e0cbc89f6f5a367/label_studio_converter/converter.py#L526-L541 to take rotation into consideration.

makseq commented 1 year ago

Could you please check this PR: https://github.com/heartexlabs/label-studio-converter/pull/134 ?

rgaiacs commented 1 year ago

@makseq Thanks for the reply and the pull request. I tested the pull request and it didn't work.

rotation

The above figure illustrates the user case. User creates the red box and rotate it into the blue box. When exporting to COCO and YOLO, we want to export the green box.

makseq commented 1 year ago

@rgaiacs thank you for your great investigation and finalizing my PR!