[Python] PIL split拆分RGBA图像通道的Bug

博客首页 » Python PIL split拆分RGBA图像通道的Bug

发布于 25 Sep 2015 12:01
标签 blog
Python PIL库在split拆分RGBA图像通道时报如下的错,这是一个Bug。通过修改PIL源码可以解决。

Traceback (most recent call last):
  File "D:\home\dev\python\winsdkey\vcode.py", line 17, in <module>
    vcode = pytesseract.image_to_string(image)
  File "D:\usr\local\Python27\lib\site-packages\pytesseract\pytesseract.py", line 143, in image_to_string
    if len(image.split()) == 4:
  File "D:\usr\local\Python27\lib\site-packages\PIL\Image.py", line 1497, in split
    if self.im.bands == 1:
AttributeError: 'NoneType' object has no attribute 'bands'

修改 D:\usr\local\Python27\lib\site-packages\PIL\Image.py

    def split(self):
        "Split image into bands"
 
        self.load() # move to here. 
        if self.im.bands == 1:
            ims = [self.copy()]
        else:
            ims = []
            # move "self.load()" out of if-else statement
            for i in range(self.im.bands):
                ims.append(self._new(self.im.getband(i)))
        return tuple(ims)

参考资料:

http://blog.sina.com.cn/s/blog_463041490102uxt6.html


本页面的文字允许在知识共享 署名-相同方式共享 3.0协议和GNU自由文档许可证下修改和再使用,仅有一个特殊要求,请用链接方式注明文章引用出处及作者。请协助维护作者合法权益。


系列文章

文章列表

  • Python PIL split拆分RGBA图像通道的Bug

这篇文章对你有帮助吗,投个票吧?

rating: 0+x

留下你的评论

Add a New Comment