离线标注版 labelme 和网页标注版 LabelMeAnnotationTool 的标注格式是不同的。以下代码实现通过网页标注版 labelme 输出的 xml 格式标注文件,输出掩码照片。
代码地址:labelme_xml2mask.py
# -*- coding: utf-8 -*-
def xml2mask(image_path, xml, id2class_dict):
class2id_dict = {value: key for key, value in id2class_dict.items()}
tree = ET.parse(xml)
root = tree.getroot()
img_size = cv2.imread(image_path).shape
height = img_size[0]
weight = img_size[1]
mask = np.zeros([height, weight], dtype=np.uint8)
for instance in root.iter('object'):
if (instance.findall('deleted')[0].text) == '0':
classname = instance.findall('