Skip to content

Commit 65244fe

Browse files
committed
initial work into converters
1 parent e07b11e commit 65244fe

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

labelbox/data/serialization/labelbox_v1/objects.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,54 @@ def validate_subclasses(cls, value, field):
4242
return value
4343

4444

45+
class _TIPoint(BaseModel):
46+
coordinates: List[float]
47+
48+
49+
class LBV1TIPoint(BaseModel):
50+
point: _TIPoint
51+
52+
def to_common(self) -> Point:
53+
lng, lat = self.point.coordinates
54+
return Point(x=lng, y=lat)
55+
56+
57+
class LBV1TILine(BaseModel):
58+
line: List[_TIPoint]
59+
60+
def to_common(self) -> Line:
61+
return Line(points=[
62+
LBV1TIPoint(point=point).to_common() for point in self.line
63+
])
64+
65+
66+
class LBV1TIPolygon(BaseModel):
67+
polygon: List[List[_TIPoint]]
68+
69+
def to_common(self) -> Polygon:
70+
for inner_list in self.polygon:
71+
return Polygon(points=[
72+
LBV1TIPoint(point=point).to_common() for point in inner_list
73+
])
74+
75+
76+
class LBV1TIRectangle(BaseModel):
77+
bbox: List[List[_TIPoint]]
78+
79+
def to_common(self) -> Rectangle:
80+
inner_list = self.bbox[0]
81+
start = inner_list[0]
82+
end = inner_list[2]
83+
for inner_list in self.bbox:
84+
return Rectangle(start=LBV1TIPoint(point=start).to_common(),
85+
end=LBV1TIPoint(point=end).to_common())
86+
87+
for inner_list in self.polygon:
88+
return Polygon(points=[
89+
LBV1TIPoint(point=point).to_common() for point in inner_list
90+
])
91+
92+
4593
class _Point(BaseModel):
4694
x: float
4795
y: float
@@ -194,7 +242,8 @@ def from_common(cls, text_entity: TextEntity,
194242

195243
class LBV1Objects(BaseModel):
196244
objects: List[Union[LBV1Line, LBV1Point, LBV1Polygon, LBV1Rectangle,
197-
LBV1TextEntity, LBV1Mask]]
245+
LBV1TextEntity, LBV1Mask, LBV1TIPoint, LBV1TILine,
246+
LBV1TIPolygon, LBV1TIRectangle]]
198247

199248
def to_common(self) -> List[ObjectAnnotation]:
200249
objects = [

0 commit comments

Comments
 (0)