SimpleCV教程NamError:未定义全局名称“pil”

时间:2013-09-20 17:13:51

标签: python binary simplecv

我尝试使用SimpleCV示例代码(http://www.simplecv.org/),它显示了SimpleCV阈值函数,阈值方法根据图像的亮度将图像中的每个像素设置为黑色或白色。

但它不起作用

这样的错误:

ERROR:

Traceback (most recent call last):

File "Camera_1.py", line 37, in <module>

img = Image('http://i.imgur.com/lfAeZ4n.png')

File "c:\Python27\lib\site-packages\SimpleCV\ImageClass.py", line 686, in __in

it__

`source = pil.open(im).convert("RGB")`

NameError: global name 'pil' is not defined

这样的代码:

from SimpleCV import Image, Color, Display

# Make a function that does a half and half image.
def halfsies(left,right): 
    result = left
    # crop the right image to be just the right side.
    crop   = right.crop(right.width/2.0,0,right.width/2.0,right.height)
    # now paste the crop on the left image.
    result = result.blit(crop,(left.width/2,0))
    # return the results.
    return result
# Load an image from imgur.
img = Image('http://i.imgur.com/lfAeZ4n.png')
# binarize the image using a threshold of 90 
# and invert the results.
output = img.binarize(90).invert()
# create the side by side image.
result = halfsies(img,output)
# show the resulting image.
result.show()
# save the results to a file. 
result.save('juniperbinary.png')

Code in here

1 个答案:

答案 0 :(得分:1)

您需要安装Python Imaging Library(PIL),它是第三方模块。我认为SimpleCV应该作为整个安装过程的一部分安装PIL,但是PIL是设置的更奇怪的程序之一。

尝试从命令行输入以下内容:

pip install pil

或者,您可以使用binary安装。

如果仍然无效,请尝试安装pillow,这是一个更友好且积极开发的PIL分支:

pip install pillow
相关问题