1、两个文件夹的图像合并到另一个文件夹。
import os import shutil import numpy as np Adir = './trainA/' Bdir = './trainB/' ABdir = './train0/' num=0 for fi in os.listdir(Adir): shutil.copy(Adir+fi,ABdir+str(num)+'_'+fi) shutil.copy(Bdir+'0'+fi[1:],ABdir+str(num)+'_'+'0'+fi[1:]) num = num + 1 print (num)
2、筛选结束的图像分开到两个文件夹中。
import os import shutil import numpy as np Adir = './trainA/' Bdir = './trainB/' ABdir = './train0/' for fi in os.listdir(ABdir): length = len(fi.spilt('_')[0]) if fi.spilt('_')[1]=='0': shutil.copy(ABdir+fi,Bdir+fi[length+1:]) else: shutil.copy(ABdir+fi,Adir+fi[length+1:])