我是 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)
但我遇到以下错误:无法导入名称“imread”
我已经成功安装了 numpy 和 scipy。
最佳答案
您还需要安装 PIL (Pillow),因为 scipy
使用它来读取图像:
pip install Pillow
注意 from the docs :
imread uses the Python Imaging Library (PIL) to read an image. The following notes are from the PIL documentation.
但是,您可能需要考虑切换到 scipy.imageio.imread
,因为 scipy.misc.imread
是 deprecated :
imread is deprecated! imread is deprecated in SciPy 1.0.0, and will be removed in 1.2.0. Use imageio.imread instead
关于python - 将图像导入 python :cannot import name 'imread' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48923151/