from PIL import Image
imageFile ="C:\Users\Abhi\Desktop\cbir-p\asf.jpg"
xsize, ysize=Image.open(imageFile).size
此代码适用于某些图像。如果我对不同的图像使用相同的代码,则报告错误。
错误:
Traceback (most recent call last):
File "C:\Users\Abhi\Desktop\cbir-p\im1.py", line 5, in <module>
xsize , ysize = Image.open(imageFile).size
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1993, in open
fp = builtins.open(fp, "rb")
IOError: [Errno 22] invalid mode ('rb') or filename: 'C:\\Users\\Abhi\\Desktop\\cbir-p\x07sd.jpg'
答案 0 :(得分:3)
使用原始字符串作为文件名。
imageFile = r'C:\Users\Abhi\Desktop\cbir-p\asf.jpg'
答案 1 :(得分:0)
import os, sys
from PIL import Image
files = os.listdir('D:\Python')
for file in files:
img = Image.open('D:\\Python\\0.jpg')