转换图片格式的时候,出现错误:TypeError: Cannot handle this data type: (1, 1), <i8
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Traceback (most recent call last): File "/Users/mcj/opt/anaconda3/envs/py3/lib/python3.6/site-packages/PIL/Image.py", line 2714, in fromarray mode, rawmode = _fromarray_typemap[typekey] KeyError: ((1, 1), '<i8') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/mcj/.nutstore/.nutstore/荔枝面条/07 学习资料/07 代码/PycharmProject/算法集合/将图片转为矩阵/imgtomatrix.py", line 27, in <module> loadImage() File "/Users/mcj/.nutstore/.nutstore/荔枝面条/07 学习资料/07 代码/PycharmProject/算法集合/将图片转为矩阵/imgtomatrix.py", line 22, in loadImage new_im = Image.fromarray(data) File "/Users/mcj/opt/anaconda3/envs/py3/lib/python3.6/site-packages/PIL/Image.py", line 2716, in fromarray raise TypeError("Cannot handle this data type: %s, %s" % typekey) TypeError: Cannot handle this data type: (1, 1), <i8 进程已结束,退出代码 1 |
解决如下:
将:new_im = Image.fromarray(data)
改为:new_im = Image.fromarray(np.uint8(data))
本文最后更新于2020年5月3日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!