【发布时间】:2016-08-12 04:38:24
【问题描述】:
def image_to_laplacian(filename):
with open(filename, 'r', encoding="latin-1") as f:
s = f.read()
img = sc.misc.imread(f)
image_to_laplacian('images/bw_3x3.png')
生产:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
“images/bw_3x3.png”是我在 Pinta 中制作的 3x3 图像。我尝试打开从 Google 图片获得的 cat.jpg,但出现了同样的错误。
我还尝试使用"encoding="latin-1" 作为打开的参数,基于我在 SO 上阅读的内容;我能够打开文件,但我
读取失败并出现异常
OSError: 无法识别图像文件 <_io.textiowrapper name="images/bw_3x3.png" mode="r" encoding="latin-1">
【问题讨论】: