che*_*fei 6 python image scipy imshow centos7
我正在测试scipy.misc.imshow,我得到RuntimeError:无法执行图像查看器.
我正在使用Python3.4并在CentOS 7上运行它.
import scipy.misc
img = scipy.misc.imread('Data/cat.jpg')
assert len(img.shape) == 3
img_resized = scipy.misc.imresize(img, (224, 224))
img_answer = (img_resized/255.0).astype('float32')
scipy.misc.imshow(img_answer)
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
sh: see: command not found
Traceback (most recent call last):
File "/usr/local/pycharm/helpers/pydev/pydev_run_in_console.py", line 71, in <module>
globals = run_file(file, None, None)
File "/usr/local/pycharm/helpers/pydev/pydev_run_in_console.py", line 31, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "/usr/local/pycharm/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/root/PycharmProjects/myVQA/testgood.py", line 6, in <module>
scipy.misc.imshow(img_answer)
File "/usr/lib64/python3.4/site-packages/scipy/misc/pilutil.py", line 442, in imshow
raise RuntimeError('Could not execute image viewer.')
RuntimeError: Could not execute image viewer.
Run Code Online (Sandbox Code Playgroud)
它说see没有找到命令.seeCentOS7上安装的命令在哪里?我该如何解决这个问题?
我试图添加SCIPY_PIL_IMAGE_VIEWER=/bin/eog到/etc/profile
,但它似乎没有什么帮助.
您可以使用matplotlib.pyplot作为使用SciPy的imshow方法的替代方法.
import scipy.misc
img = scipy.misc.imread('Data/cat.jpg')
assert len(img.shape) == 3
img_resized = scipy.misc.imresize(img, (224, 224))
img_answer = (img_resized/255.0).astype('float32')
import matplotlib.pyplot as plt
plt.imshow(np.uint8(img_tinted))
plt.show()
Run Code Online (Sandbox Code Playgroud)
PS如果我们直接将图像绘制成图形plt.imshow(img_tinted),那么如果呈现给它的数据不是单元格8,它有时会产生奇怪的结果.因此,为了防止这种情况,我们明确地np.uint8转换为图像,如plt.imshow(np.uint8(img_tinted))
以下图像显示缺少np.uint8时的输出
我通过以下方式解决了我的问题:
1 将以下内容添加到/etc/profile
SCIPY_PIL_IMAGE_VIEWER=/bin/eog
export SCIPY_PIL_IMAGE_VIEWER
Run Code Online (Sandbox Code Playgroud)
2 重启
如果您不导出 SCIPY_PIL_IMAGE_VIEWER,
cmd = os.environ.get('SCIPY_PIL_IMAGE_VIEWER', 'see')
Run Code Online (Sandbox Code Playgroud)
将无法识别 SCIPY_PIL_IMAGE_VIEWER