当前位置: 代码迷 >> 综合 >> Small-code: 计算xml格式数据集中每一类的数量
  详细解决方案

Small-code: 计算xml格式数据集中每一类的数量

热度:92   发布时间:2023-12-27 04:46:49.0

该代码用于计算VOC格式数据集中每一类标注框的数量:

# -*- coding:utf-8 -*-
import os
import xml.etree.ElementTree as ET
import numpy as np# np.set_printoptions(suppress=True, threshold=np.nan)
import matplotlib
from PIL import Imagedef parse_obj(xml_path, filename):tree = ET.parse(xml_path + filename)objects = []for obj in tree.findall('object'):obj_struct = {}obj_struct['name'] = obj.find('name').textobjects.append(obj_struct)return objectsdef read_image(image_path, filename):im = Image.open(image_path + filename)W = im.size[0]H = im.size[1]area = W * Him_info = [W, H, area]return im_infoif __name__ == '__main__':# xml_path = 'E:\\dataset\\solar_cell_EL_image\\PVELAD\\EL2021\\test\\Annotations\\'xml_path =  'E:\\dataset\\solar_cell_EL_
  相关解决方案