与PIL一起使用多重处理 [英] Using multiprocessing with the PIL

查看:56
本文介绍了与PIL一起使用多重处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码对一堆Python Imaging Library(PIL)图像对象执行(独立)操作.我想尝试使用并行处理来加快速度,因此我在下面的多处理模块上进行了阅读:

I have some code that does (independent) operations on a bunch of Python Imaging Library (PIL) Image objects. I would like to try and speed this up using parallel processing, so I read up on the multiprocessing module below:

http://docs.python.org/library/multiprocessing.html

但是我仍然不清楚如何使用多重处理来解决这个问题.

But it's still not very clear to me how to use multiprocessing for this problem.

从概念上讲,看起来我可以使用multiprocessing.Image对象队列并使用工作池.但是Image对象似乎无法挑剔":

Conceptually, it looks like I could use a multiprocessing.Queue of Image objects and use a Pool of workers. But the Image objects seem 'unpickelable':

UnpickleableError: Cannot pickle <type 'ImagingCore'> objects

是否有更好的并行处理PIL图像的方法?

Is there a better way to process PIL images in parallel?

推荐答案

如果从文件中获取图像对象,则只需将文件名发送给工作人员,然后让他们自己打开图像即可.

If you get the image objects from files, you can just send the filenames to the workers and let them open the images themselves.

否则,您可以发送图像数据(使用Image.getdata())以及大小和像素格式,并让工作人员使用Image.new()Image.putdata()重建图像.

Otherwise, you can send the image data (with Image.getdata()), along with the size and pixel format, and have the workers reconstruct the image using Image.new() and Image.putdata().

这篇关于与PIL一起使用多重处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆