在pascal voc xml中注释图像

时间:2015-08-26 02:42:19

标签: image-processing machine-learning computer-vision object-detection

我需要一个工具来用矩形边界框注释图像。输出将采用pascal voc xml格式。注释和图像将成为卷积神经网络用于对象检测的训练数据集的一部分。我将自己手动注释图像。

我考虑了以下工具,但它们不支持pascal-voc。

LabelmeSlothPilabNo name

是否有可以节省时间的注释工具?

2 个答案:

答案 0 :(得分:9)

答案 1 :(得分:7)

此python代码片段将Sloth json转换为pascal voc xml。

  def make_anno():
    zind = 0
    for z in data:
        print zind
        filename = data[zind]["filename"]
        print filename
        head, tail = os.path.split(filename)
        basename, file_extension = os.path.splitext(tail)    
        f = open(basename + '.xml','w') 
        line = "<annotation>" + '\n'
        f.write(line)
        line = '\t\t<folder>' + "folder" + '</folder>' + '\n'
        f.write(line)
        line = '\t\t<filename>' + tail + '</filename>' + '\n'
        f.write(line)
        line = '\t\t<source>\n\t\t<database>Source</database>\n\t</source>\n'
        f.write(line)
        im=Image.open('/home/location/VOCdevkit/newdataset/img/' + tail)
        (width, height) = im.size
        line = '\t<size>\n\t\t<width>'+ str(width) + '</width>\n\t\t<height>' + str(height) + '</height>\n\t'
        line += '\t<depth>Unspecified</depth>\n\t</size>'
        f.write(line)
        line = '\n\t<segmented>Unspecified</segmented>'
        f.write(line)
        ind = 0
        for i in data[zind]["annotations"]:
            line = '\n\t<object>'
            line += '\n\t\t<name>Name</name>\n\t\t<pose>Unspecified</pose>'
            line += '\n\t\t<truncated>Unspecified</truncated>\n\t\t<difficult>Unspecified</difficult>'
            xmin = (data[zind]["annotations"][ind]["x"])
            line += '\n\t\t<bndbox>\n\t\t\t<xmin>' + str(xmin) + '</xmin>'
            ymin = (data[zind]["annotations"][ind]["y"])
            line += '\n\t\t\t<ymin>' + str(ymin) + '</ymin>'
            width = (data[zind]["annotations"][ind]["width"])
            height = (data[zind]["annotations"][ind]["height"])
            xmax = xmin + width
            ymax = ymin + height
            line += '\n\t\t\t<xmax>' + str(xmax) + '</xmax>'
            line += '\n\t\t\t<ymax>' + str(ymax) + '</ymax>'
            line += '\n\t\t</bndbox>'
            line += '\n\t</object>'     
            f.write(line)
            ind +=1
            f.close()
        zind +=1