我正在测试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
但似乎没有任何帮助。
答案 0 :(得分:8)
您可以使用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()
P.S。如果我们直接将图像绘制为plt.imshow(img_tinted)
,那么如果呈现给它的数据不是以unit8的形式,它有时会产生奇怪的结果。因此,为了防止这种情况,我们明确地将np.uint8
投射到图像,例如plt.imshow(np.uint8(img_tinted))
以下图像显示缺少np.uint8
时的输出答案 1 :(得分:1)
我解决了我的问题:
1将以下内容添加到/ etc / profile
% sed -E 's_/[^,]*__' <<<'name/name, val1, val2'
name, val1, val2
2次重启
如果您不导出SCIPY_PIL_IMAGE_VIEWER,
SCIPY_PIL_IMAGE_VIEWER=/bin/eog
export SCIPY_PIL_IMAGE_VIEWER
无法识别SCIPY_PIL_IMAGE_VIEWER
答案 2 :(得分:0)
以下内容对我也有效(比使用matplotlib更轻更快):
(word1|word2|...|wordn)
然后我可以使用scipy的imshow()。