更改图像及xml名称,并移动图形及对应xml
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)