我正在测试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)

我得到一个错误:
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.

它说找不到see命令。 CentOS7上的see命令安装在哪里?我该如何解决该问题?

我试图将SCIPY_PIL_IMAGE_VIEWER=/bin/eog添加到/etc/profile但这似乎无济于事。

最佳答案

您可以使用matplotlib.pyplot替代使用SciPy's 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()

python - scipy.misc.imshow RuntimeError (&#39;Could not execute image view&#39;)-LMLPHP => python - scipy.misc.imshow RuntimeError (&#39;Could not execute image view&#39;)-LMLPHP

P.S.如果我们将图像直接绘制为plt.imshow(img_tinted),则如果提供给它的数据不是unit8形式的,则有时可能会得出奇怪的结果。因此,为防止这种情况,我们将np.uint8显式转换为图像,例如plt.imshow(np.uint8(img_tinted))
下图显示了在没有np.uint8的情况下的输出

python - scipy.misc.imshow RuntimeError (&#39;Could not execute image view&#39;)-LMLPHP

关于python - scipy.misc.imshow RuntimeError ('Could not execute image view'),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40229630/

10-12 17:12