您的位置:首页 > 博客中心 > APP开发 >

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

时间:2022-03-13 20:37

 

 

 


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)




相关推荐

电脑软件

本类排行

今日推荐

热门手游