这篇文章主要介绍了使用python可以使用什么包实现批量读取图片,文中介绍的非常详细,对正在学习python的小伙伴非常有参考价值,感兴趣的小伙伴们一定要看完!
我们知道在Python中可以使用multiprocessing库实现批量读取图片。
multiprocessing包是Python中的多进程管理包。与threading.Thread类似,它可以利用multiprocessing.Process对象来创建一个进程。
实现代码如下:
#coding=utf-8 ''''' #==================== #测试一下进程 #==================== ''' from multiprocessing import Pool import scipy from scipy import misc import os import time import glob from scipy import ndimage start = time.time() def get_image_paths(folder): #这个函数的作用的获取文件的列表,注释部分是获取 # return (os.path.join(folder, f) # for f in os.listdir(folder) # if 'png' in f) return glob.glob(os.path.join(folder, '*.png')) def create_read_img(filename): im = misc.imread(filename) #读取图像 img_rote = ndimage.rotate(im, 90) #旋转90度 #scipy.misc.imsave('...',img_rote) img_path = '存放图像的目录/' imgs = get_image_paths(img_path) print imgs pool = Pool() pool.map(create_read_img,imgs) pool.close() pool.join() # for i in imgs: # create_read_img(i) 这部分是循环,可以用来对比时间 end = time.time() print end - start
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。