码迷,mamicode.com
首页 > 移动开发 > 详细

更改图像及xml名称,并移动图形及对应xml

时间:2020-06-04 01:36:12      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:desktop   jpg   img   put   element   pre   更改   dir   parse   

 

 

 


from xml.etree.ElementTree import ElementTree
import cv2
import os

def read_xml(in_path):
tree = ElementTree()
tree.parse(in_path)
return tree

def write_xml(tree, out_path):
tree.write(out_path)

path_input=‘C:/Users/51102/Desktop/STR01‘
path_out=‘C:/Users/51102/Desktop/456‘

names=os.listdir(path_input)
for name in names:
a, b = os.path.splitext(name)
if b == ‘.jpg‘:
if a+‘.jpg‘ in names and a+‘.xml‘ in names:
img=cv2.imread(path_input+‘/‘+a+‘.jpg‘)
cv2.imwrite(path_out+‘/‘+a+‘_repeat.jpg‘,img)
tree=read_xml(path_input+‘/‘+a+‘.xml‘)
write_xml(tree,path_out+‘/‘+a+‘_repeat.xml‘)
print(a)




更改图像及xml名称,并移动图形及对应xml

标签:desktop   jpg   img   put   element   pre   更改   dir   parse   

原文地址:https://www.cnblogs.com/tangjunjun/p/13040857.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!