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

时间:2020-06-04 01:36:12   收藏:0   阅读:68

 

 

 


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)




评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!