# -*- coding:utf-8 -*-
from PIL import Image
import os.path
import glob
import xml.etree.ElementTree as ET
import xml.dom.minidom
# # 开始序号
i = '000001'
xmldir = "D:\\qingdao\\qingdao_project\\VOCdevkit\\VOC2007\\Annotations"
imgsdir = "D:\\qingdao\\qingdao_project\\VOCdevkit\\VOC2007\\JPEGImages"
for xmlfile in os.listdir(xmldir):
xmlname = os.path.splitext(xmlfile)[0]
# print(xmlname)
for imagefile in os.listdir(imgsdir):
imagename = os.path.splitext(imagefile)[0]
# print(imagename)
if imagename == xmlname:
# 修改图片文件名
# 图片文件名修改前后的路径
olddir = os.path.join(os.path.abspath(imgsdir), imagename + ".jpg")
newdir = os.path.join(os.path.abspath(imgsdir), '%06d' % int(i)+".jpg")
os.rename(olddir, newdir)
print(xmlfile, '----->', '%06d' % int(i) + '.jpg')
根据数据增强的voc修改xml的filename
最新推荐文章于 2023-03-25 18:03:12 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)