您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页voc格式 从xml中得到所有类别对象的样本数

voc格式 从xml中得到所有类别对象的样本数

来源:二三四教育网
from __future__ import division
import os
from PIL import Image
import xml.dom.minidom
import numpy as np

AnnoPath = 'F:/code/transfor/VOC2007/Annotations/'

xmllist = os.listdir(AnnoPath)
num_plane =0
num_oil =0
for xmli in xmllist:
    xmlfile = AnnoPath + xmli[:-4] + '.xml'

    DomTree = xml.dom.minidom.parse(xmlfile)
    annotation = DomTree.documentElement

    filenamelist = annotation.getElementsByTagName('filename')  # [<DOM Element: filename at 0x381f788>]
    filename = filenamelist[0].childNodes[0].data
    objectlist = annotation.getElementsByTagName('object')

    i = 1
    for objects in objectlist:
        # print objects

        namelist = objects.getElementsByTagName('name')
        # print 'namelist:',namelist
        objectname = namelist[0].childNodes[0].data
        #print(objectname)
        if objectname=='plane':
            num_plane=num_plane+1
        else:num_oil = num_oil+1
print('num_plane=',num_plane,'num_oil=',num_oil)

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务