small-code: 目标检测将xml转化为csv

目标检测将xml转化为csv:

import os
import glob
import pandas as pd
import xml.etree.ElementTree as ET
import shutil

def xml_to_csv(path):  ### path存放xml文件路径
    xml_list = []
    for xml_file in glob.glob(path + '/*.xml'):
        print(xml_file)
        xml_list1 = []
        tree = ET.parse(xml_file)
        root = tree.getroot()
        id = str(os.path.basename(xml_file).split('.')[0])
        i = 1
        for member in root.findall('object'):
            # try:
            width = int(root.find('size')[0].text)
            height = int(root.find('size')[1].text)

            if i==1:
                value = (
                         member[0].text+' '+
                         str(float(member[4][0].text)/width)+' '+
                         str(float(member[4][1].text)/height)+' '+
                         str(floa

你可能感兴趣的:(人工智能,数据集,目标检测,xml,目标检测,python,机器学习,工业异常检测)