xml_show.py
import os
import xml.dom.minidom
import cv2 as cv
ImgPath = '1/'
AnnoPath = '2/' #xml文件地址
save_path = '3/'
imagelist = os.listdir(ImgPath)
for image in imagelist:
image_pre, ext = os.path.splitext(image)
imgfile = ImgPath + image
xmlfile = AnnoPath + image_pre + '.xml'
print(image)
# 打开xml文档
DOMTree = xml.dom.minidom.parse(xmlfile)
# 得到文档元素对象
collection = DOMTree.documentElement
# 读取图片
img = cv.imread(imgfile)
filenamelist = collection.getElementsByTagName("filename")
filename = filenamelist[0].childNodes[0].data
print(filename)
# 得到标签名为object的信息
objectlist = collection.getElementsByTagName("object")
for objects in objectlist:
# 每个object中得到子标签名为name的信息
namelist = objects.getElementsByTagName('name')
# 通过此语句得到具体的某个n