不从打印返回任何内容

时间:2018-12-07 19:35:53

标签: python-3.x

我正在尝试读取图像并进行处理,然后输出处理后的图像。但是,该代码在我的计算机上不返回任何内容(在工作目录中可以找到zip文件)。我试图将文件中的项目打印出来。但是什么也没打印。谁能告诉我这是怎么回事???非常感谢!

from PIL import ImageFile
from PIL import Image
from zipfile import ZipFile

import random

import os
import argparse

ImageFile.LOAD_TRUNCATED_IMAGES = True
Image.MAX_IMAGE_PIXELS = None


def main():
    ziplist = []
    for file in os.listdir():
        if file.endswith(".zip") and file.startswith("train"):
            ziplist.append(file)
    print(ziplist)
    # import data
    labels = []  #list of file names without suffix
    #img = []

    #os.mkdir(args.thumb_dir)
    #os.mkdir(args.patch_dir)
    count = 0
    for file in ziplist:
        count += 1
        #os.mkdir(args.thumb_dir + str(file))
        #os.mkdir(args.patch_dir + str(file))
        with ZipFile(file, 'r') as archive:
            for item in archive.namelist():
                #labels = []  #list of file names without suffix
                #img = []
                print(item)
                #  labels.append(os.path.splitext(entry.filename)[0])
                if (".jpg" in item or ".JPG" in item):
                    with archive.open(item) as file:
                        ima = Image.open(file)
                        print(ima)
                        # Save thumbnail
                        ima.resize((227,227)).save(args.thumb_dir, item)

                        ima = ima.resize((928,928))
                        randnum = random.randint(227,701)
                        box = (randnum-113,randnum-113,randnum+114,randnum+114)
                        region = ima.crop(box)
                        #img.append(np.asarray(region))

                        # Save crop
                        region.save(os.path.join(args.patch_dir, item))

        # save using json
        #f=open('file.json','w')
        #print(img)
        #img = img.tolist() # nested lists with same data, indices
        #labels = labels.tolist() # nested lists with same data, indices
        #file_path = "file.json" ## your path variable
        #json.dump(img, codecs.open(file_path, 'w', encoding='utf-8'), cls=NDArrayEncoder, sort_keys=True, indent=4)
        #jsonify({labels: img})### this saves the array in .json format
        #f.write(json.dumps({"labels":labels,"img":img}))
        #f.close()  

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("--patch_dir", type=str, help="path_dir",
                        default="path")
    parser.add_argument("--thumb_dir", type=str, help="path",
                        default="path")
    args = parser.parse_args()
    main()`enter code here`

0 个答案:

没有答案