赞
踩
在搭建之前的代码环境时,报错:
ERROR: Could not find a wersion that satisfies the requirement PIL(from versions: none)
ERROR: No matching distribution found for PIL
ERROR: Could not find a wersion that satisfies the requirement PIL(from versions: none)
ERROR: No matching distribution found for PIL
截图如下:
主要报错信息内容翻译如下所示:
ERROR: Could not find a wersion that satisfies the requirement PIL(from versions: none)
ERROR: No matching distribution found for PIL
翻译:
错误:找不到满足要求PIL的版本(来自版本:none)
错误:找不到与PIL匹配的分布
经过查阅资料,发现是模块名字错了。
附:
PIL即Python Imageing Library,而Pillow是PIL的一个分支。Pillow提供了常见的图像读取和处理的操作,它比opencv更为轻巧,而且可以与ipython notebook无缝集成。
小伙伴们按下面的解决方法即可解决!!!
使用正确的名字pillow
安装。
修改前:
pip install PIL
修改后:
pip install pillow
使用Image.open()读取图片存储为一个对象,配合numpy的使用案例如下。
from PIL import Image #导入PIL库
import numpy as np
img = Image.open('../xx.jpg') # 读取图片
imgL = Image.open('../xx.jpg').convert('L') # 读取图片灰度图
onvert('L') # 读取图片灰度图
imgL.show() # 展示灰度图
img.show() # 展示画布
imgData = np.array(img) # 将对象img转化为RGB像素值矩阵
print(imgData) # 输出所有像素的RGB值
imgN = Image.fromarray(imgData) # 将RGB像素值矩阵转化为对象imgN
imgN.save('xxx.jpg') # 储存为文件xxx.jpg
r ,g ,b = img.split() # 分离通道
img = Image.merge("RGB", (b, g, r)) # 合并通道
原图如下:
灰度图如下:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。