Explorar o código

use pycocotools API

iscrowd is 0 when segmentation is polygons encoded
Lingjie Zhu %!s(int64=6) %!d(string=hai) anos
pai
achega
9885f0703e
Modificáronse 1 ficheiros con 3 adicións e 9 borrados
  1. 3 9
      examples/instance_segmentation/labelme2coco.py

+ 3 - 9
examples/instance_segmentation/labelme2coco.py

@@ -135,13 +135,7 @@ def main():
             mask = np.asfortranarray(mask.astype(np.uint8))
             mask = pycocotools.mask.encode(mask)
             area = float(pycocotools.mask.area(mask))
-
-            bbox = []
-            for points in segmentations[label]:
-                bbox.extend(points)
-            bbox = np.asarray(bbox).reshape((-1, 2))
-            xmin, ymin = np.amin(bbox, axis=0).tolist();
-            xmax, ymax = np.amax(bbox, axis=0).tolist();
+            bbox = pycocotools.mask.toBbox(mask).flatten().tolist()
 
             data['annotations'].append(dict(
                 id=len(data['annotations']),
@@ -149,8 +143,8 @@ def main():
                 category_id=cls_id,
                 segmentation=segmentations[label],
                 area=area,
-                bbox=[xmin, ymin, xmax - xmin, ymax - ymin],
-                iscrowd=None,
+                bbox=bbox,
+                iscrowd=0,
             ))
 
     with open(out_ann_file, 'w') as f: