gpt4 book ai didi

python-imaging-library - Python 图像库 : AttributeError: 'NoneType' object has no attribute XXX

转载 作者:行者123 更新时间:2023-12-03 23:04:15 26 4
gpt4 key购买 nike

我用PIL打开了一张图片,但是当我尝试使用split()时拆分 channel 我收到以下错误:AttributeError: 'NoneType' object has no attribute 'bands'

import Image
img = Image.open('IMG_0007.jpg')

img.split()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)

/home/blum/<ipython console> in <module>()

/usr/lib/python2.6/dist-packages/PIL/Image.pyc in split(self)
1495 "Split image into bands"
1496
-> 1497 if self.im.bands == 1:
1498 ims = [self.copy()]
1499 else:

AttributeError: 'NoneType' object has no attribute 'bands'

最佳答案

通过谷歌搜索,我发现了这个 comment on SO, stating that PIL is sometimes 'lazy'打开后“忘记”加载。所以你必须这样做:

import Image
img = Image.open('IMG_0007.jpg')
img.load()
img.split()

也请+1原始评论!这个人做了真正的工作。

关于python-imaging-library - Python 图像库 : AttributeError: 'NoneType' object has no attribute XXX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12413649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com