@@ -18,7 +18,7 @@ class Annotation(BaseModel):
1818 classId : Optional [int ]
1919 x : Optional [Any ]
2020 y : Optional [Any ]
21- points : Optional [ Dict ]
21+ points : Any
2222 attributes : Optional [List [Any ]] = []
2323 keyframe : bool = False
2424
@@ -30,10 +30,11 @@ class FrameAnnotation(BaseModel):
3030
3131class VideoFrameGenerator :
3232 def __init__ (self , annotation_data : dict , fps : int ):
33- self .validate_annotations (annotation_data )
3433 self .id_generator = iter (itertools .count (0 ))
3534 self ._annotation_data = annotation_data
36- self .duration = annotation_data ["metadata" ]["duration" ] / (1000 * 1000 )
35+ duration = annotation_data ["metadata" ]["duration" ]
36+ duration = 0 if not duration else duration
37+ self .duration = duration / (1000 * 1000 )
3738 self .fps = fps
3839 self .ratio = 1000 * 1000 / fps
3940 self ._frame_id = 1
@@ -42,12 +43,6 @@ def __init__(self, annotation_data: dict, fps: int):
4243 self ._mapping = {}
4344 self ._process ()
4445
45- @staticmethod
46- def validate_annotations (annotation_data : dict ):
47- duration = annotation_data ["metadata" ].get ("duration" )
48- if duration is None :
49- raise AppException ("Video not annotated yet" )
50-
5146 def get_frame (self , frame_no : int ):
5247 try :
5348 return self .annotations [frame_no ]
@@ -81,10 +76,9 @@ def _interpolate(
8176 "x" : round (data ["x" ] + steps ["x" ] * idx , 2 ),
8277 "y" : round (data ["y" ] + steps ["y" ] * idx , 2 ),
8378 }
84- elif annotation_type in (AnnotationTypes .POLYGON , AnnotationTypes .POLYLINE ):
85- tmp_data ["points" ] = [
86- point + steps [idx ] * 2 for idx , point in enumerate (data ["points" ])
87- ]
79+ else :
80+ tmp_data ["points" ] = data ["points" ]
81+
8882 annotations [frame_idx ] = Annotation (
8983 instanceId = instance_id ,
9084 type = annotation_type ,
0 commit comments