HumanSignal / label-studio

Label Studio is a multi-type data labeling and annotation tool with standardized output format
https://labelstud.io
Apache License 2.0
19.35k stars 2.4k forks source link

YOLO Export format rotates annotations wrong if image is not quadratic #2293

Open ferenc-hechler opened 2 years ago

ferenc-hechler commented 2 years ago

Describe the bug When exporting rotate annotations in YOLO format, the annotation is calculated wrong. The reason is, that the rotation is done with the percentages of the image height and width. But if the image is not quadratic this deforms the annotation.

To Reproduce Steps to reproduce the behavior:

  1. Upload an Image in format 1000x500 pixels
  2. create three annotations: a) X=200,Y=100, W=300, H=100, rot=0 a) X=200,Y=100, W=300, H=100, rot=90 a) X=100,Y=100, W=100, H=300, rot=0
  3. save annotations and export YOLO format
  4. Open the YOLO zip file and look at the generated annotatins. It looks like this label-id/center-x%/center-y%/width%/height% 0 0.35 0.3 0.3 0.2 1 0.1 0.35 0.2 0.3 2 0.15 0.5 0.1 0.6

Expected behavior The second line (90 degree rotated) and the third line (not rotated) should be identical. So it should be 0 0.35 0.3 0.3 0.2 1 0.15 0.5 0.1 0.6 2 0.15 0.5 0.1 0.6

Screenshots Annotations in Label-Studio. One horizontal 300x100, one horizontal 300x100 rotated by 90 degree and one vertical 300x100. The vertical and rotated annotation overlap exactly grafik

Visualized results of the YOLO lines:

Line1 for label 0 (horizotal): x=35% y=30%, width=30%, height=20% grafik

Line2 for label 1 (horizontal-rot90): x=10% y=35%, width=20%, height=30% grafik

Line 3 for label 2 (vertical): x=15% y=50%, width=10%, height=60% grafik

Environment (please complete the following information):

Additional context To fix this problem, the coordinates have to be scaled to a common ratio before rotating. So that 10% in horizontal direction have the same length as 10% in vertical direction.

ferenc-hechler commented 2 years ago

Looks like the export is generated in another project: label-studio-converter

The corresponding lines should be here (not yet tested): https://github.com/heartexlabs/label-studio-converter/blob/598420012b5cb6e9cd5283e62887ff33af36d0bb/label_studio_converter/converter.py#L649

Should I create a new Issue in label-studio-converter?

makseq commented 2 years ago

Thank you very much for your issue. Yes, it would be great if you could create a PR!

hellkrusher commented 1 year ago

I'm also having this same issue with rotated images and yolo export. Was there ever a fix or workaround?