将图像导入python:无法导入名称'imread'

moh*_*mlo 10 python

我是python的新手,我想导入图像。

import numpy as np
from scipy.misc import imread, imsave, imresize
# Read an JPEG image into a numpy array
img = imread('Cover.jpg')
print(img.dtype, img.shape)
Run Code Online (Sandbox Code Playgroud)

但是我遇到以下错误:cannot import name 'imread' 我已经成功安装了numpy和scipy。

Fly*_*ler 10

您还需要安装PIL(枕头),因为这是scipy用来读取图像的方法:

pip install Pillow
Run Code Online (Sandbox Code Playgroud)

来自文档的注释:

imread使用Python图像库(PIL)读取图像。以下注释来自PIL文档。

但是,您可能要考虑切换到,scipy.imageio.imread因为scipy.misc.imread弃用

不推荐使用imread!在SciPy 1.0.0中已弃用了imread,在1.2.0中将其删除。改用imageio.imread


小智 6

用:

from imageio import imread
Run Code Online (Sandbox Code Playgroud)

它对我有用。