我就废话不多说了,还是直接上代码吧! import os
import xml.dom.minidom
import cv2 as cv
ImgPath = 'C:/Users/49691/Desktop/gangjin/gangjin_test/JPEGImages/'
AnnoPath = 'C:/Users/49691/Desktop/gangjin/gangjin_test/Annotations/' #xml文件地址
save_path = ''
def draw_anchor(ImgPath,AnnoPath,save_path):
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].