1.创建空文件夹(参照其他文件)
import os
path = "E:\\blog\\data_sets\\single\\"
path3 = "D:\\demon\\result_single\\nei"
filelist = os.listdir(path) #该文件夹下所有的文件(包括文件夹)
for file in filelist:
os.makedirs(path3+file)
2.调整图片大小(遍历文件)
path="E:\\blog\\data_sets\\single_data\\icp\\jian\\"
for i in range(255):
from PIL import Image
im = Image.open(path+str(i+1)+".jpg")
out = im.resize((512, 512), Image.ANTIALIAS)
path2=path+str(i+1)+".jpg"
out.save(path2)
2.调整图片大小(分文件)
import os
from PIL import Image
path="D:/pengxiang/pycd/jian/"
dist=os.listdir(path)
img=["image-01.jpeg", "image-02.jpeg", "image-03.jpeg", "image-04.jpeg", "image-05.jpeg"]
for file in dist:
for i in range(5):
path1=path+file+"/"+img[i]
im = Image.open(path1)
out = im.resize((128, 128), Image.ANTIALIAS)
out.save(path1)
3.拷贝文件
import os
from shutil import copy
path = "E:/blog/data_sets/single/"
path3 = "D:/demon/single_rename/"
filelist = os.listdir(path) #该文件夹下所有的文件(包括文件夹)
for file in filelist:
path1=path+file+"/"+file+".jpg"
path2=path3+file+"/"+file+".jpg"
copy(path1, path2)
4.读取文本
path = "D:\\pengxiang\\test"
path1 = "D:\\pengxiang\\data_set\\dataneipylddmm\\"
f1 = open("D:\\pengxiang\\data_set\\result_wenjian_jian.txt", 'r')
second = []
for i in range(255):
str1 = f1.readline()
b = str1[14:20]
second.append(b)
path2 = path + second[i] + img[i % 5]
path3 = path1 + str(i + 1) + "_result.png"
RMSE(path2, path3)