8
8
ANNOTATION_ID_KEY ,
9
9
ANNOTATIONS_KEY ,
10
10
BOX_TYPE ,
11
+ CUBOID_TYPE ,
11
12
DATASET_ITEM_ID_KEY ,
13
+ DIMENSIONS_KEY ,
12
14
GEOMETRY_KEY ,
13
15
HEIGHT_KEY ,
14
16
INDEX_KEY ,
18
20
MASK_URL_KEY ,
19
21
METADATA_KEY ,
20
22
POLYGON_TYPE ,
23
+ POSITION_KEY ,
21
24
REFERENCE_ID_KEY ,
22
25
TYPE_KEY ,
23
26
VERTICES_KEY ,
24
27
WIDTH_KEY ,
25
28
X_KEY ,
29
+ YAW_KEY ,
26
30
Y_KEY ,
31
+ Z_KEY ,
27
32
)
28
33
29
34
@@ -43,6 +48,8 @@ def from_json(cls, payload: dict):
43
48
return BoxAnnotation .from_json (payload )
44
49
elif payload .get (TYPE_KEY , None ) == POLYGON_TYPE :
45
50
return PolygonAnnotation .from_json (payload )
51
+ elif payload .get (TYPE_KEY , None ) == CUBOID_TYPE :
52
+ return CuboidAnnotation .from_json (payload )
46
53
else :
47
54
return SegmentationAnnotation .from_json (payload )
48
55
@@ -125,6 +132,7 @@ def to_payload(self) -> dict:
125
132
class AnnotationTypes (Enum ):
126
133
BOX = BOX_TYPE
127
134
POLYGON = POLYGON_TYPE
135
+ CUBOID = CUBOID_TYPE
128
136
129
137
130
138
@dataclass # pylint: disable=R0902
@@ -187,6 +195,20 @@ def to_payload(self) -> dict:
187
195
return {X_KEY : self .x , Y_KEY : self .y }
188
196
189
197
198
+ @dataclass
199
+ class Point3D :
200
+ x : float
201
+ y : float
202
+ z : float
203
+
204
+ @classmethod
205
+ def from_json (cls , payload : Dict [str , float ]):
206
+ return cls (payload [X_KEY ], payload [Y_KEY ], payload [Z_KEY ])
207
+
208
+ def to_payload (self ) -> dict :
209
+ return {X_KEY : self .x , Y_KEY : self .y , Z_KEY : self .z }
210
+
211
+
190
212
@dataclass
191
213
class PolygonAnnotation (Annotation ):
192
214
label : str
@@ -241,6 +263,50 @@ def to_payload(self) -> dict:
241
263
return payload
242
264
243
265
266
+ @dataclass
267
+ class CuboidAnnotation (Annotation ):
268
+ label : str
269
+ position : Point3D
270
+ dimensions : Point3D
271
+ yaw : float
272
+ reference_id : Optional [str ] = None
273
+ item_id : Optional [str ] = None
274
+ annotation_id : Optional [str ] = None
275
+ metadata : Optional [Dict ] = None
276
+
277
+ def __post_init__ (self ):
278
+ self ._check_ids ()
279
+ self .metadata = self .metadata if self .metadata else {}
280
+
281
+ @classmethod
282
+ def from_json (cls , payload : dict ):
283
+ geometry = payload .get (GEOMETRY_KEY , {})
284
+ return cls (
285
+ label = payload .get (LABEL_KEY , 0 ),
286
+ position = Point3D .from_json (geometry .get (POSITION_KEY , {})),
287
+ dimensions = Point3D .from_json (geometry .get (DIMENSIONS_KEY , {})),
288
+ yaw = payload .get (YAW_KEY , 0 ),
289
+ reference_id = payload .get (REFERENCE_ID_KEY , None ),
290
+ item_id = payload .get (DATASET_ITEM_ID_KEY , None ),
291
+ annotation_id = payload .get (ANNOTATION_ID_KEY , None ),
292
+ metadata = payload .get (METADATA_KEY , {}),
293
+ )
294
+
295
+ def to_payload (self ) -> dict :
296
+ return {
297
+ LABEL_KEY : self .label ,
298
+ TYPE_KEY : CUBOID_TYPE ,
299
+ GEOMETRY_KEY : {
300
+ POSITION_KEY : self .position ,
301
+ DIMENSIONS_KEY : self .dimensions ,
302
+ YAW_KEY : self .yaw ,
303
+ },
304
+ REFERENCE_ID_KEY : self .reference_id ,
305
+ ANNOTATION_ID_KEY : self .annotation_id ,
306
+ METADATA_KEY : self .metadata ,
307
+ }
308
+
309
+
244
310
def check_all_annotation_paths_remote (
245
311
annotations : Sequence [Union [Annotation ]],
246
312
):
0 commit comments