33from typing import Any , Dict , List , Tuple , Union
44import base64
55import numpy as np
6+ from py import process
67
78from pydantic import BaseModel
89from PIL import Image
910
11+ from labelbox .data .annotation_types .data .video import VideoData
12+
1013from ...annotation_types .data import ImageData , TextData , MaskData
1114from ...annotation_types .ner import TextEntity
1215from ...annotation_types .types import Cuid
1316from ...annotation_types .geometry import Rectangle , Polygon , Line , Point , Mask
14- from ...annotation_types .annotation import ClassificationAnnotation , ObjectAnnotation
17+ from ...annotation_types .annotation import ClassificationAnnotation , ObjectAnnotation , VideoObjectAnnotation
1518from .classification import NDSubclassification , NDSubclassificationType
1619from .base import DataRow , NDAnnotation
1720
@@ -118,6 +121,72 @@ def from_common(cls, rectangle: Rectangle,
118121 classifications = classifications )
119122
120123
124+ class NDFrameRectangle (BaseModel ):
125+ frame : int
126+ bbox : Bbox
127+
128+
129+ class NDSegment (BaseModel ):
130+ keyframes : List [NDFrameRectangle ]
131+
132+
133+ class NDSegments (NDBaseObject ):
134+ segments : List [NDSegment ]
135+
136+ # uuid: str
137+ # schema_id: str
138+
139+ # def process_segment(self, segment: List[VideoObjectAnnotation]):
140+ # """
141+ # We only care about the annotation.value and frame once we make it here
142+ # """
143+ # # for annotation in segment:
144+ # return [{
145+ # "frame":
146+ # annotation.frame,
147+ # "bbox":
148+ # Bbox(top=annotation.value.start.y,
149+ # left=annotation.value.start.x,
150+ # height=annotation.value.end.y - annotation.value.start.y,
151+ # width=annotation.value.end.x - annotation.value.start.x)
152+ # } for annotation in segment]
153+
154+ def to_common (self ):
155+ pass
156+
157+ @classmethod
158+ def from_common (cls , segments : List [VideoObjectAnnotation ], data : VideoData ,
159+ feature_schema_id : Cuid , extra : Dict [str ,
160+ Any ]) -> "NDSegments" :
161+ print (f"\n WE MADE IT HERE TO SEGMENTS\n " )
162+ # for segment in segments:
163+ # print("\nSEGMENT\n", segment)
164+ # processed_segment = cls.process_segment(cls, segment)
165+
166+ # segments = [{
167+ # "keyframes": [{
168+ # "frame": 3,
169+ # "bbox": Bbox(top=0, left=0, height=1, width=1)
170+ # }]
171+ # }, {
172+ # "keyframes": [{
173+ # "frame": 5,
174+ # "bbox": Bbox(top=0, left=0, height=3, width=5)
175+ # }]
176+ # }]
177+
178+ segments = [{"keyframes" : segment } for segment in segments ]
179+
180+ print ("wew\n " , segments [0 ], "sss\n " )
181+
182+ a = cls (segments = segments ,
183+ dataRow = DataRow (id = data .uid ),
184+ schema_id = feature_schema_id ,
185+ uuid = extra .get ('uuid' ))
186+ print ("A\n " , a , "\n Z" )
187+ return a
188+
189+
121190class _URIMask (BaseModel ):
122191 instanceURI : str
123192 colorRGB : Tuple [int , int , int ]
@@ -211,6 +280,21 @@ def from_common(
211280 cls , annotation : ObjectAnnotation , data : Union [ImageData , TextData ]
212281 ) -> Union [NDLine , NDPoint , NDPolygon , NDRectangle , NDMask , NDTextEntity ]:
213282 obj = cls .lookup_object (annotation )
283+
284+ #if it is video segments
285+ if (obj == NDSegments ):
286+ print ("hello i am ndsegment" )
287+ #look into segment of segments
288+ #look into annotations of segment
289+ #check and validate that there are no subclasses
290+ #new method for processing segments ?
291+
292+ return obj .from_common (
293+ annotation ,
294+ data ,
295+ feature_schema_id = annotation [0 ][0 ].feature_schema_id ,
296+ extra = annotation [0 ][0 ].extra )
297+
214298 subclasses = [
215299 NDSubclassification .from_common (annot )
216300 for annot in annotation .classifications
@@ -221,20 +305,32 @@ def from_common(
221305
222306 @staticmethod
223307 def lookup_object (annotation : ObjectAnnotation ) -> "NDObjectType" :
224- result = {
225- Line : NDLine ,
226- Point : NDPoint ,
227- Polygon : NDPolygon ,
228- Rectangle : NDRectangle ,
229- Mask : NDMask ,
230- TextEntity : NDTextEntity
231- }.get (type (annotation .value ))
308+ if isinstance (annotation , list ):
309+ result = NDSegments
310+ else :
311+ result = {
312+ Line : NDLine ,
313+ Point : NDPoint ,
314+ Polygon : NDPolygon ,
315+ Rectangle : NDRectangle ,
316+ Mask : NDMask ,
317+ TextEntity : NDTextEntity
318+ }.get (type (annotation .value ))
232319 if result is None :
233320 raise TypeError (
234321 f"Unable to convert object to MAL format. `{ type (annotation .value )} `"
235322 )
236323 return result
237324
325+ # @staticmethod
326+ # def process_segments(segments: List[List[VideoObjectAnnotation]]):
327+ # for segment in segments:
328+ # for annotation in segment:
329+ # subclasses = [
330+ # NDSubclassification.from_common(annot)
331+ # for annot in annotation.classifications
332+ # ]
333+
238334
239335NDObjectType = Union [NDLine , NDPolygon , NDPoint , NDRectangle , NDMask ,
240336 NDTextEntity ]
0 commit comments