gpt4 book ai didi

python - scipy.misc.imshow 运行时错误 ('Could not execute image view' )

转载 作者:太空狗 更新时间:2023-10-29 22:21:21 25 4
gpt4 key购买 nike

我正在测试 scipy.misc.imshow我得到了RuntimeError: Could not execute image viewer

我正在使用 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()

Original Image => Output Image

附言如果我们直接将图像绘制为 plt.imshow(img_tinted),那么如果提供给它的数据不是 unit8 的形式,它有时可能会给出奇怪的结果。因此,为了防止这种情况,我们明确地将 np.uint8 转换为图像,例如 plt.imshow(np.uint8(img_tinted))

下图显示了没有 np.uint8 时的输出

enter image description here

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com