提交 aef52165 编写于 作者: L Lingjie Zhu 提交者: Kentaro Wada

add missing 'bbox' field in COCO annotation

"bbox": [x, y, width, height]
bbox coordinates are measured from the top left image corner and 0-indexed
上级 8435d75e
......@@ -136,13 +136,21 @@ def main():
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();
data['annotations'].append(dict(
id=len(data['annotations']),
image_id=image_id,
category_id=cls_id,
segmentation=segmentations[label],
area=area,
bbox=[xmin, ymin, xmax - xmin, ymax - ymin],
iscrowd=None,
image_id=image_id,
category_id=cls_id,
))
with open(out_ann_file, 'w') as f:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册