66from typing import List
77from .utils import simplify
88
9- from .. import ApiClient , BoundingBox , File , Segmentations , Where , Project
9+ from .. import ApiClient , BoundingBox , File , Where , Project
1010
1111try :
1212 from pycocotools .coco import COCO
@@ -211,7 +211,9 @@ def import_coco(
211211 dt_mask = coco .annToMask (anno_copy )
212212 dt_segmentations .append (dt_mask )
213213 if source .type == "PaperBox" :
214- dt_bbox .append (source .xywh )
214+ dt_bbox .append (
215+ [source .x , source .y , source .width , source .height ]
216+ )
215217
216218 print (f"[{ dt_file .name } ] Importing { len (coco_annotations )} coco annotations." )
217219 new_annotations = []
@@ -228,7 +230,7 @@ def import_coco(
228230 created_bbox = False
229231 created_segmentation = False
230232
231- if import_bbox :
233+ if import_bbox and len ( anno [ "bbox" ]) == 4 :
232234 bbox = BoundingBox .xywh (* anno ["bbox" ])
233235 if not check_iou or (
234236 check_iou and not has_bbox (bbox , dt_bbox , max_iou )
@@ -252,21 +254,23 @@ def import_coco(
252254 if import_bbox and not created_bbox :
253255 continue
254256
255- if import_segmentation :
257+ if import_segmentation and len ( anno [ "segmentation" ]) > 0 :
256258 anno ["segmentation" ] = simplify_segmentation (
257259 anno ["segmentation" ], tolerance = simplify_tolerance
258260 )
259- anno_mask = coco .annToMask (anno )
260-
261- if not check_iou or (
262- check_iou and not has_mask (anno_mask , dt_segmentations , max_iou )
263- ):
264- print (f"[{ dt_file .name } ] Adding new segmentation." )
265- path_data = segmentation_to_points (anno ["segmentation" ])
266- created_segmentation = True
267- annotation ["sources" ].append (
268- {"type" : "PaperSegmentations" , "data" : {"pathData" : path_data }}
269- )
261+
262+ if len (anno ["segmentation" ]) > 0 :
263+ anno_mask = coco .annToMask (anno )
264+
265+ if not check_iou or (
266+ check_iou and not has_mask (anno_mask , dt_segmentations , max_iou )
267+ ):
268+ print (f"[{ dt_file .name } ] Adding new segmentation." )
269+ path_data = segmentation_to_points (anno ["segmentation" ])
270+ created_segmentation = True
271+ annotation ["sources" ].append (
272+ {"type" : "PaperSegmentations" , "data" : {"pathData" : path_data }}
273+ )
270274
271275 if created_segmentation or created_bbox :
272276 # dt_file.add(dt_anno)
0 commit comments