Closed patel-zeel closed 4 months ago
Have you found a solution? I have a similar problem with my annotations. They look nice and well centered in LabelStudio but when I plot them in python, they look offset like 100 pixels.
@luforestal Since even YOLO OBB export is not yet implemented (https://github.com/HumanSignal/label-studio-converter/pull/281), we use the following workaround:
# @Author: Zeel B Patel, https://patel-zeel.github.io/
import numpy as np
import torch
from ultralytics.utils.ops import xywhr2xyxyxyxy from typing import Union
label_map = {"Class A": 0, "Class B": 1}
def label_studio_to_yolo_obb(x1, y1, w, h, r, label) -> Union[np.ndarray, torch.Tensor]: """ Convert from Label studio CSV (x1, y1, w, h, r) to YOLO OBB (x1, y1, x2, y2, x3, y3, x4, y4) format
x1: x-cordinate of one corner of the box, range(0, 100)
y1: y-cordinate of one corner of the box, range(0, 100)
w: width of the box, range(0, 100)
h: height of the box, range(0, 100)
r: rotation angle of the box in degrees
label: label of the box
Returns: Label in YOLO OBB format -> array([label_id, x1, y1, x2, y2, x3, y3, x4, y4])
"""
if isinstance(x1, torch.Tensor):
handle = torch
handle.concatenate = torch.cat
get_array = lambda x: torch.tensor(x)
else:
handle = np
get_array = lambda x: np.array(x)
r = handle.radians(r)
cos_rot = handle.cos(r)
sin_rot = handle.sin(r)
x_c = x1 + w / 2 * cos_rot - h / 2 * sin_rot
y_c = y1 + w / 2 * sin_rot + h / 2 * cos_rot
xywhr = get_array([x_c, y_c, w, h, r])
xyxyxyxy = xywhr2xyxyxyxy(xywhr).ravel()
# Normalize to range(0, 1)
xyxyxyxy = xyxyxyxy / 100
label_id = get_array([label_map[label]])
yolo_label = handle.concatenate([label_id, xyxyxyxy])
return yolo_label
* Once we get x1, y1, x2, y2, x3, y3, x4, y4, you can get the bounds and put it inside the XML programatically
```py
xmax = max([x1, x2, x3, x4])
xmin = min([x1, x2, x3, x4])
ymax = max([y1, y2, y3, y4])
ymin = min([y1, y2, y3, y4])
Thanks for sharing your workaround @patel-zeel, we will update when YOLO OBB export is finally implemented. Otherwise, closing this issue for now!
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.
Screenshots
Labeling in label-studio
PASCAL VOC XML
Ploting PASCAL VOC and YOLO labels after exports
Environment (please complete the following information):