从不同的目录下取文件,然后把复制文件增加文件尺寸
#encoding=utf-8
import copy
import os
import shutil
import xml.dom.minidom
from xml.dom.minidom import parse
path="d:testVOC2007_new_import-1VOC2007"
def get_file(*args):
for i in list(*args):
for root,dirs,files in os.walk(path+"//"+i,topdown=False):
for filename in files:
if os.path.isfile(os.path.join(root,filename)):
#复制文件增加文件大小
for i in range(1,4):
shutil.copyfile(os.path.join(root,filename),os.path.join(root,"".join(filename.split(".")[0]) + "-" + str(i) + "." + "".join(filename.split(".")[1])))
if filename.split(".")[1] != "xml":
# 获取图片大小
#sizes = round(os.path.getsize(os.path.join(root,filename)) / 1024.0,2)
name = "".join(filename.split(".")[0]) + "-" + str(i) + "." + "".join(filename.split(".")[1])
print name
#解析xml文件
#dom=xml.dom.minidom.parse(path+"Annotations"+"".join(filename.split(".")[0])+"-"+str(i)+".xml")
#width=dom.getElementsByTagName(‘width‘)[0].firstChild.data
#height=dom.getElementsByTagName(‘height‘)[0].firstChild.data
#depth=dom.getElementsByTagName(‘depth‘)[0].firstChild.data
#解析后写到config文件里
#with open("d:testVOC2007_new_importVOC2007_train.txt",‘a+‘) as fp:
#fp.write("VOC2007/"+root.split("")[-1]+"/"+"".join(filename.split(".")[0])+"-"+str(i)+"."+"".join(filename.split(".")[1])
+" "+"VOC2007/Annotations/"+"".join(filename.split(".")[0])+"-"+str(i)+".xml"+" "+str(width)+" "+str(height)+" "+str(depth)+" "+name+" "+str(sizes)+"kb"+"n")
get_file(["Annotations-1","JPEGImages-1"])