I try to use SimpleCV example's code(http://www.simplecv.org/), which shows the SimpleCV threshold function, the threshold method sets each pixel in an image to black or white depending on its brightness.

But it doesn't work

Error like this:

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

Code like this:

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

有帮助吗?

解决方案

You need to install the Python Imaging Library (PIL), which is a 3rd party module. I think SimpleCV is supposed to install PIL as part of the overall installation process, but PIL is one of those weirder programs to set up.

Try typing in the following from the command line:

pip install pil

Alternatively, you can install using the binary.

If that still doesn't work, try installing pillow, which is a friendlier and actively-developed fork of PIL:

pip install pillow
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top