更改目标检测标签xml文件中的path

实现目标

根据labelme或labelimg生成的xml文件中,有对应图像的路径。当别人帮你打标签时,对应图像的路径是别人电脑上面的,并非是你想要的。 
说明路径备注
原始xml文件存放路径D:\aaa\source/别人帮你打的标签
现在xml文件存放路径D:\aaa\target/你自己想要放的位置
图像路径D:\aaa\img/假设你最开始图像就是在这里

在这里插入图片描述

代码

import xml.etree.ElementTree as ET
import os
# xml文件原始存放路径
source_path = r"D:\aaa\yuanshi/"
# 修改后的xml文件存放路径
target_path = r"D:\aaa\target/"  
img_path = r"D:\aaa\img/"  
files = os.listdir(source_path)
for xmlFile in files:
    if xmlFile.endswith('.xml'):
        tree = ET.ElementTree(file=source_path + xmlFile)
        root = tree.getroot()
        root[0].text = 'images'
        root[2].text = img_path + xmlFile
        root[2].text = root[2].text.replace('xml', 'jpg')
        tree.write(target_path + xmlFile)
print('全部替换完成')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值