label-studio icon indicating copy to clipboard operation
label-studio copied to clipboard

PASCAL VOC XML is incorrect for OBB labels

Open patel-zeel opened this issue 1 year ago • 0 comments

Describe the bug PASCAL VOC XML export generates incorrect values for Oriented Bounding Boxes (OBB) labels.

To Reproduce

Expected behavior I am not sure if PASCAL VOC XML supports OBB labels.

If it supports:
    It should correctly convert the labels.
else:
    It should first convert the labels to axis-aligned bounding boxes and then get the bounds (just like YOLO export).
    It may show a warning for this implicit conversion.

Screenshots

Labeling in label-studio

image

PASCAL VOC XML

<?xml version="1.0" encoding="utf-8"?>
<annotation>
<folder>images</folder>
<filename>2af821c3-28.2077.44.png</filename>
<source>
<database>MyDatabase</database>
<annotation>COCO2017</annotation>
<image>flickr</image>
<flickrid>NULL</flickrid>
<annotator>1</annotator>
</source>
<owner>
<flickrid>NULL</flickrid>
<name>Label Studio</name>
</owner>
<size>
<width>1120</width>
<height>1120</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>Airplane</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>514</xmin>
<ymin>141</ymin>
<xmax>613</xmax>
<ymax>193</ymax>
</bndbox>
</object>
<object>
<name>Car</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>819</xmin>
<ymin>317</ymin>
<xmax>918</xmax>
<ymax>379</ymax>
</bndbox>
</object>
</annotation>

Ploting PASCAL VOC and YOLO labels after exports

import matplotlib.pyplot as plt
img = plt.imread("images/2af821c3-28.2077.44.png")

fig, ax = plt.subplots(figsize=(8, 8))
plt.imshow(img)

# <xmin>514</xmin>
# <ymin>141</ymin>
# <xmax>613</xmax>
# <ymax>193</ymax>

x1 = 514
y1 = 141
x2 = 613
y2 = 193

plt.plot([x1, x2], [y1, y1], c='g')
plt.plot([x2, x2], [y1, y2], c='g')
plt.plot([x2, x1], [y2, y2], c='g')
plt.plot([x1, x1], [y1, y2], c='g')

# <xmin>819</xmin>
# <ymin>317</ymin>
# <xmax>918</xmax>
# <ymax>379</ymax>

x1 = 819
y1 = 317
x2 = 918
y2 = 379

plt.plot([x1, x2], [y1, y1], c='b')
plt.plot([x2, x2], [y1, y2], c='b')
plt.plot([x2, x1], [y2, y2], c='b')
plt.plot([x1, x1], [y1, y2], c='b', label='PASCAL VOC XML labels')

### YOLO
# 0 0.5042087542087542 0.14983164983164982 0.08922558922558928 0.047138047138047125
# 1 0.7449494949494948 0.33417508417508407 0.10281727886993011 0.10189583947751818
x1 = (0.5042087542087542 - 0.08922558922558928/2) * 1120
x2 = (0.5042087542087542 + 0.08922558922558928/2) * 1120
y1 = (0.14983164983164982 - 0.047138047138047125/2) * 1120
y2 = (0.14983164983164982 + 0.047138047138047125/2) * 1120

plt.plot([x1, x2], [y1, y1], c='g', linestyle='--', linewidth=5)
plt.plot([x2, x2], [y1, y2], c='g', linestyle='--', linewidth=5)
plt.plot([x2, x1], [y2, y2], c='g', linestyle='--', linewidth=5)
plt.plot([x1, x1], [y1, y2], c='g', linestyle='--', linewidth=5)

x1 = (0.7449494949494948 - 0.10281727886993011/2) * 1120
x2 = (0.7449494949494948 + 0.10281727886993011/2) * 1120
y1 = (0.33417508417508407 - 0.10189583947751818/2) * 1120
y2 = (0.33417508417508407 + 0.10189583947751818/2) * 1120

plt.plot([x1, x2], [y1, y1], c='b', linestyle='--', linewidth=5)
plt.plot([x2, x2], [y1, y2], c='b', linestyle='--', linewidth=5)
plt.plot([x2, x1], [y2, y2], c='b', linestyle='--', linewidth=5)
plt.plot([x1, x1], [y1, y2], c='b', label="YOLO labels", linestyle='--', linewidth=5)

plt.legend()
plt.savefig("tmp.png", dpi=200)

image

Environment (please complete the following information):

  • OS: Ubuntu 20.04.6 LTS
  • Label Studio Version 1.12.1

patel-zeel avatar May 23 '24 07:05 patel-zeel