@@ -56,14 +56,14 @@ def get_frame(self, frame_no: int):
5656 return self .annotations [frame_no ]
5757
5858 def _interpolate (
59- self ,
60- class_name : str ,
61- from_frame : int ,
62- to_frame : int ,
63- data : dict ,
64- instance_id : int ,
65- steps : dict = None ,
66- annotation_type : str = "bbox" ,
59+ self ,
60+ class_name : str ,
61+ from_frame : int ,
62+ to_frame : int ,
63+ data : dict ,
64+ instance_id : int ,
65+ steps : dict = None ,
66+ annotation_type : str = "bbox" ,
6767 ) -> dict :
6868 annotations = {}
6969 for idx , frame_idx in enumerate (range (from_frame + 1 , to_frame ), 1 ):
@@ -78,10 +78,12 @@ def _interpolate(
7878 elif annotation_type == AnnotationTypes .POINT :
7979 tmp_data = {
8080 "x" : round (data ["x" ] + steps ["x" ] * idx , 2 ),
81- "y" : round (data ["y" ] + steps ["y" ] * idx , 2 )
81+ "y" : round (data ["y" ] + steps ["y" ] * idx , 2 ),
8282 }
8383 elif annotation_type in (AnnotationTypes .POLYGON , AnnotationTypes .POLYLINE ):
84- tmp_data ["points" ] = [point + steps [idx ] * 2 for idx , point in enumerate (data ["points" ])]
84+ tmp_data ["points" ] = [
85+ point + steps [idx ] * 2 for idx , point in enumerate (data ["points" ])
86+ ]
8587 annotations [frame_idx ] = Annotation (
8688 instanceId = instance_id ,
8789 type = annotation_type ,
@@ -107,7 +109,9 @@ def get_median(self, annotations: List[dict]) -> dict:
107109 if len (annotations ) == 1 :
108110 return annotations [0 ]
109111 first_annotations = annotations [:1 ][0 ]
110- median = (first_annotations ["timestamp" ] // self .ratio ) * self .ratio + self .ratio / 2
112+ median = (
113+ first_annotations ["timestamp" ] // self .ratio
114+ ) * self .ratio + self .ratio / 2
111115 median_annotation = first_annotations
112116 distance = abs (median - first_annotations ["timestamp" ])
113117 for annotation in annotations [1 :]:
@@ -131,29 +135,49 @@ def merge_first_frame(frames_mapping):
131135 return frames_mapping
132136
133137 def _interpolate_frames (
134- self , from_frame , from_frame_no , to_frame , to_frame_no , annotation_type , class_name , instance_id
138+ self ,
139+ from_frame ,
140+ from_frame_no ,
141+ to_frame ,
142+ to_frame_no ,
143+ annotation_type ,
144+ class_name ,
145+ instance_id ,
135146 ):
136147 steps = None
137148 frames_diff = to_frame_no - from_frame_no
138- if annotation_type == AnnotationTypes .BBOX and from_frame .get ("points" ) and to_frame .get ("points" ):
149+ if (
150+ annotation_type == AnnotationTypes .BBOX
151+ and from_frame .get ("points" )
152+ and to_frame .get ("points" )
153+ ):
139154 steps = {}
140155 for point in "x1" , "x2" , "y1" , "y2" :
141156 steps [point ] = round (
142- (to_frame ["points" ][point ] - from_frame ["points" ][point ]) / frames_diff , 2
157+ (to_frame ["points" ][point ] - from_frame ["points" ][point ])
158+ / frames_diff ,
159+ 2 ,
143160 )
144161 elif annotation_type == AnnotationTypes .POINT :
145162 steps = {
146163 "x" : (to_frame ["x" ] - from_frame ["x" ]) / frames_diff ,
147- "y" : (to_frame ["y" ] - from_frame ["y" ]) / frames_diff
164+ "y" : (to_frame ["y" ] - from_frame ["y" ]) / frames_diff ,
148165 }
149166 elif annotation_type in (AnnotationTypes .POLYGON , AnnotationTypes .POLYLINE ):
150167 steps = [
151168 (to_point - from_point ) / frames_diff
152- for from_point , to_point in zip (from_frame ["points" ], to_frame ["points" ])
169+ for from_point , to_point in zip (
170+ from_frame ["points" ], to_frame ["points" ]
171+ )
153172 ]
154173 return self ._interpolate (
155- class_name = class_name , from_frame = from_frame_no , to_frame = to_frame_no , data = from_frame ,
156- instance_id = instance_id , steps = steps , annotation_type = annotation_type
174+ class_name = class_name ,
175+ from_frame = from_frame_no ,
176+ to_frame = to_frame_no ,
177+ data = from_frame ,
178+ instance_id = instance_id ,
179+ steps = steps ,
180+ annotation_type = annotation_type ,
157181 )
158182
159183 def _process (self ):
@@ -185,13 +209,16 @@ def _process(self):
185209 to_frame_no = to_frame_no ,
186210 class_name = class_name ,
187211 annotation_type = annotation_type ,
188- instance_id = instance_id
212+ instance_id = instance_id ,
189213 )
190214 )
191215
192216 start_median_frame = self .get_median (frames_mapping [from_frame_no ])
193217 end_median_frame = self .get_median (frames_mapping [to_frame_no ])
194- for frame_no , frame in (from_frame_no , start_median_frame ), (last_frame_no , end_median_frame ):
218+ for frame_no , frame in (
219+ (from_frame_no , start_median_frame ),
220+ (last_frame_no , end_median_frame ),
221+ ):
195222 interpolated_frames [frame_no ] = Annotation (
196223 instanceId = instance_id ,
197224 type = annotation_type ,
0 commit comments