Trying to run simple PIL python example, can't convert jpeg to float

前端 未结 3 1995
忘了有多久
忘了有多久 2021-02-09 15:32

so I wrote a simple python script

from PIL import Image
from pylab import *
im = array(Image.open(\'sample.jpg\'))
imshow(im)

and i get this er

3条回答
  •  萌比男神i
    2021-02-09 15:53

    I know this is coming very later but I thought I should answer just in case anyone else had the same problem. I ran into the same problem and the issue was the image I loaded did not exist in the project folder.so you need to check that sample.jpg exist and that it loads properly before using it.

    if os.path.isfile('sample.jpg'): im = array(Image.open('sample.jpg'))
    if im == None or im.size == 0: 
       print 'Image loaded is empty'
       sys.exit(1)
    

提交回复
热议问题