import os
import xml.dom.minidom
import requests
AnnotationPath = '/home/huacan/VOCdevkit/VOC2007/Annotations/'
myDir = os.listdir(AnnotationPath)
for filePath in myDir:
print()
print(AnnotationPath+filePath)
dom = xml.dom.minidom.parse(AnnotationPath+filePath)
rootdata = dom.documentElement
#print(rootdata.toxml())
try:
filename = rootdata.getElementsByTagName('filename')[0].childNodes[0].data
folder = rootdata.getElementsByTagName('folder')[0].childNodes[0].data
print(folder)
newName = folder.split('_')[1]
rootdata.getElementsByTagName('name')[0].childNodes[0].data = newName
rootdata.getElementsByTagName('filename')[0].childNodes[0].data = newName+filename.lstrip('cameraCapture')
with open(AnnotationPath+filePath, 'w', encoding='utf-8') as f:
深度学习xml文件读写(VOCdevkit/VOC2007/Annotations )
最新推荐文章于 2023-03-15 11:35:27 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)