from PIL import Image import os #urlWater是水底的影像,urlImage1m的切片 def replaceImage(urlWater,urlImage,): #打开水底影像 imgWater=Image.open(urlWater) target = Image.new('RGBA', imgWater.size, (0, 0, 0, 0)) box = (0, 0, 256, 256) region = Image.open(urlImage) region = region.convert('RGBA') #将水底影像贴到透明的影像 target.paste(imgWater, box) #将水底影像贴到1m的影像 region.paste(target, box, target) region.save(urlWater) print("保存") return def matchPath(dir1,dir2): list1=[] list2=[] dir1=dir1 dir2=dir2 for root,dirs,files in os.walk(dir1): # print(root) #print(dirs) for name in files: fileName=os.path.join(root,name) list1.append(fileName) for root,dirs,files in os.walk(dir2): for name in files: fileName=os.path.join(root,name) list2.append(fileName) for i in list1: for j in list2: if(i[-13:-3]==j[-13:-3]): print("匹配") replaceImage(i,j) print("贴图完毕") return replaceImage() #dir1="G:\\Map\\Task\\0413\\底部"; #dir2="G:\\Map\\Task\\0413\\表面" dir1="G:\\Map\\Task\\0416\\HD" dir2="G:\\Map\\Task\\0416\\satellite" matchPath(dir1,dir2)