66
77from pydantic import BaseModel
88from PIL import Image
9+ from labelbox .data .annotation_types import feature
910
1011from labelbox .data .annotation_types .data .video import VideoData
1112
@@ -61,6 +62,21 @@ def from_common(cls, point: Point,
6162 classifications = classifications )
6263
6364
65+ class NDFramePoint (VideoSupported ):
66+ point : _Point
67+
68+ def to_common (self , feature_schema_id : Cuid ) -> VideoObjectAnnotation :
69+ return VideoObjectAnnotation (frame = self .frame ,
70+ keyframe = True ,
71+ feature_schema_id = feature_schema_id ,
72+ value = Point (x = self .point .x ,
73+ y = self .point .y ))
74+
75+ @classmethod
76+ def from_common (cls , frame : int , point : Point ):
77+ return cls (frame = frame , point = _Point (x = point .x , y = point .y ))
78+
79+
6480class NDLine (NDBaseObject ):
6581 line : List [_Point ]
6682
@@ -83,6 +99,25 @@ def from_common(cls, line: Line,
8399 classifications = classifications )
84100
85101
102+ class NDFrameLine (VideoSupported ):
103+ line : List [_Point ]
104+
105+ def to_common (self , feature_schema_id : Cuid ) -> VideoObjectAnnotation :
106+ return VideoObjectAnnotation (
107+ frame = self .frame ,
108+ keyframe = True ,
109+ feature_schema_id = feature_schema_id ,
110+ value = Line (points = [Point (x = pt .x , y = pt .y ) for pt in self .line ]))
111+
112+ @classmethod
113+ def from_common (cls , frame : int , line : Line ):
114+ return cls (frame = frame ,
115+ line = [{
116+ 'x' : pt .x ,
117+ 'y' : pt .y
118+ } for pt in line .points ])
119+
120+
86121class NDPolygon (NDBaseObject ):
87122 polygon : List [_Point ]
88123
@@ -153,18 +188,30 @@ def from_common(cls, frame: int, rectangle: Rectangle):
153188
154189
155190class NDSegment (BaseModel ):
156- keyframes : List [NDFrameRectangle ]
191+ keyframes : List [Union [ NDFrameRectangle , NDFramePoint , NDFrameLine ] ]
157192
158193 @staticmethod
159194 def lookup_segment_object_type (segment : List ) -> "NDFrameObjectType" :
160195 """Used for determining which object type the annotation contains
161196 returns the object type"""
162- result = {Rectangle : NDFrameRectangle }.get (type (segment [0 ].value ))
197+ result = {
198+ Rectangle : NDFrameRectangle ,
199+ Point : NDFramePoint ,
200+ Line : NDFrameLine ,
201+ }.get (type (segment [0 ].value ))
163202 return result
164203
165- def to_common (self , name : str , feature_schema_id : Cuid ):
204+ @staticmethod
205+ def segment_with_uuid (keyframe : Union [NDFrameRectangle , NDFramePoint ,
206+ NDFrameLine ], uuid : str ):
207+ keyframe .extra = {'uuid' : uuid }
208+ return keyframe
209+
210+ def to_common (self , name : str , feature_schema_id : Cuid , uuid : str ):
166211 return [
167- keyframe .to_common (name = name , feature_schema_id = feature_schema_id )
212+ self .segment_with_uuid (
213+ keyframe .to_common (name = name ,
214+ feature_schema_id = feature_schema_id ), uuid )
168215 for keyframe in self .keyframes
169216 ]
170217
@@ -188,7 +235,8 @@ def to_common(self, name: str, feature_schema_id: Cuid):
188235 result .extend (
189236 NDSegment .to_common (segment ,
190237 name = name ,
191- feature_schema_id = feature_schema_id ))
238+ feature_schema_id = feature_schema_id ,
239+ uuid = self .uuid ))
192240 return result
193241
194242 @classmethod
@@ -345,4 +393,4 @@ def lookup_object(
345393NDObjectType = Union [NDLine , NDPolygon , NDPoint , NDRectangle , NDMask ,
346394 NDTextEntity ]
347395
348- NDFrameObjectType = NDFrameRectangle
396+ NDFrameObjectType = NDFrameRectangle , NDFramePoint , NDFrameLine
0 commit comments