Skip to content

Commit f67f1dc

Browse files
committed
Add tests for ellipses
1 parent db08911 commit f67f1dc

File tree

2 files changed

+113
-2
lines changed

2 files changed

+113
-2
lines changed

tests/cvat/test_parsers.py

+28-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
parse_box,
88
parse_polygon,
99
parse_points,
10-
parse_skeleton,
10+
parse_skeleton, parse_ellipse,
1111
)
1212
from dagshub_annotation_converter.ir.image import (
1313
CoordinateStyle,
1414
IRBBoxImageAnnotation,
1515
IRSegmentationImageAnnotation,
1616
IRSegmentationPoint,
1717
IRPosePoint,
18-
IRPoseImageAnnotation,
18+
IRPoseImageAnnotation, IREllipseImageAnnotation,
1919
)
2020

2121

@@ -159,3 +159,29 @@ def test_skeleton():
159159
)
160160

161161
assert expected == actual
162+
163+
164+
def test_ellipse():
165+
data = """
166+
<ellipse label="circle1" source="manual" occluded="0" cx="392.23" cy="322.84" rx="205.06" ry="202.84" z_order="0">
167+
</ellipse>
168+
"""
169+
170+
image, annotation = to_xml(data)
171+
172+
actual = parse_ellipse(annotation, image)
173+
174+
expected = IREllipseImageAnnotation(
175+
filename="000.png",
176+
categories={"circle1": 1.0},
177+
image_width=1920,
178+
image_height=1200,
179+
coordinate_style=CoordinateStyle.DENORMALIZED,
180+
center_x=392,
181+
center_y=323,
182+
radius_x=205.06,
183+
radius_y=202.84,
184+
rotation=0.0,
185+
)
186+
187+
assert actual == expected

tests/label_studio/test_ellipse.py

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
from typing import Dict
2+
3+
import pytest
4+
5+
from dagshub_annotation_converter.formats.label_studio.ellipselabels import EllipseLabelsAnnotation
6+
from dagshub_annotation_converter.formats.label_studio.task import LabelStudioTask, parse_ls_task
7+
from dagshub_annotation_converter.ir.image import IREllipseImageAnnotation, CoordinateStyle
8+
from tests.label_studio.common import generate_annotation, generate_task
9+
10+
11+
@pytest.fixture
12+
def ellipse_annotation() -> Dict:
13+
annotation = {
14+
"x": 10,
15+
"y": 20,
16+
"radiusX": 30,
17+
"radiusY": 40,
18+
"ellipselabels": ["dog"],
19+
}
20+
21+
return generate_annotation(annotation, "ellipselabels", "deadbeef")
22+
23+
24+
@pytest.fixture
25+
def ellipse_task(ellipse_annotation) -> str:
26+
return generate_task([ellipse_annotation])
27+
28+
29+
@pytest.fixture
30+
def parsed_ellipse_task(ellipse_task) -> LabelStudioTask:
31+
return parse_ls_task(ellipse_task)
32+
33+
34+
def test_ellipse_parsing(parsed_ellipse_task):
35+
actual = parsed_ellipse_task
36+
assert len(actual.annotations) == 1
37+
assert len(actual.annotations[0].result) == 1
38+
39+
ann = actual.annotations[0].result[0]
40+
assert isinstance(ann, EllipseLabelsAnnotation)
41+
assert ann.value.x == 10
42+
assert ann.value.y == 20
43+
assert ann.value.radiusX == 30
44+
assert ann.value.radiusY == 40
45+
46+
47+
def test_ellipse_ir(parsed_ellipse_task):
48+
actual = parsed_ellipse_task.annotations[0].result[0].to_ir_annotation()
49+
50+
assert len(actual) == 1
51+
ann = actual[0]
52+
assert isinstance(ann, IREllipseImageAnnotation)
53+
54+
assert ann.center_x == 0.1
55+
assert ann.center_y == 0.2
56+
assert ann.radius_x == 0.3
57+
assert ann.radius_y == 0.4
58+
59+
60+
def test_ir_ellipse_addition():
61+
task = LabelStudioTask()
62+
ellipse = IREllipseImageAnnotation(
63+
categories={"dog": 1.0},
64+
center_x=0.1,
65+
center_y=0.2,
66+
radius_x=0.3,
67+
radius_y=0.4,
68+
rotation=60.0,
69+
image_width=100,
70+
image_height=100,
71+
coordinate_style=CoordinateStyle.NORMALIZED,
72+
)
73+
74+
task.add_ir_annotation(ellipse)
75+
76+
assert len(task.annotations) == 1
77+
assert len(task.annotations[0].result) == 1
78+
79+
ann = task.annotations[0].result[0]
80+
assert isinstance(ann, EllipseLabelsAnnotation)
81+
assert ann.value.x == 10
82+
assert ann.value.y == 20
83+
assert ann.value.radiusX == 30
84+
assert ann.value.radiusY == 40
85+
assert ann.value.rotation == 60.0

0 commit comments

Comments
 (0)