根据TXT文件将选出来的文件专门挑出来

# -*- encoding:utf-8 -*-
from PIL import Image
import os.path
import glob
import shutil
def convertjpg(src,outdir):
#     img=Image.open(jpgfile)
#     new_img=img.resize((width,height),Image.BILINEAR)
#     new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))
# for jpgfile in glob.glob("D:/python/*.jpg"):
#         convertjpg(jpgfile,"D:/newfile")
        f3 = open('selet10000.txt', 'r')
        line2 = f3.readlines()  # 10000行
        # label2=[eval(line.split()[0].strip()) for line in line2]
        for line in line2:
            label3 = (line.split()[0].strip())
#             label3=str(label2)
            (filepath, tempfilename) = os.path.split(label3)
#             file_suffix = os.path.splitext(label3)[0]
#             print(filepath)
            img=Image.open(os.path.join(src,label3))
#             img=Image.open(filepath)
            if os.path.exists(os.path.join(outdir,filepath)):
                shutil.copy(os.path.join(src,label3), os.path.join(outdir,filepath))
            else:
                os.makedirs(os.path.join(outdir,filepath))
                shutil.copy(os.path.join(src,label3), os.path.join(outdir,filepath))

convertjpg("../dataset","../selectnewdata")


你可能感兴趣的:(代码)