# -*- coding: utf-8 -*-
"""
将文件夹内所有XML文件的信息记录到CSV文件中
"""
import os
import glob
import pandas as pd
import xml.etree.ElementTree as ET
os.chdir('C:\workspace\VOC2007_pedestrian_headshoulder\Annotations')
path = 'C:\workspace\VOC2007_pedestrian_headshoulder\Annotations'
def xml_to_csv(path):
xml_list = []
for xml_file in glob.glob(path + '/*.xml'):
tree = ET.parse(xml_file)
root = tree.getroot()
for member in root.findall('object'):
value = (root.find('filename').text,
float(root.find('size')[0].text),
float(root.find('size')[1].text),
member[0].text,
float(member[4][0].text),
float(member[4][1].text),
float(member[4][2].text),
float(member[4][3].text)
)
xml_list.append(value)
column_name = ['filename', 'width', 'height', 'class', 'xmin', 'ymin', 'xmax', 'ymax']
xml_df = pd.DataFrame(xml_list, columns=column_name)
return xml_df
def main():
image_path = path
xml_df = xml_to_csv(image_path)
xml_df.to_csv('pedestrian_headshoulder.csv', index=None)
print('Successfully converted xml to csv.')
main()
数据集制作之xml文件转化为csv
猜你喜欢
转载自blog.csdn.net/Michelexie/article/details/83502684
今日推荐
周排行