VSCode - 在调试时显示图像

raa*_*aaj 8 python visual-studio-code

我目前正在使用 Visual Studio 代码来调试 python 文件。该 python 文件中有一个 numpy 图像。当我尝试导入 matplotlib 来显示图像时,它不显示:

- plt.imshow(pred_scores)
<matplotlib.image.AxesImage object at 0x7f3d43e691d0>
- plt.show()
None
- pred_scores
array([[0., 0., 0., ..., 0., 0., 0.],
       [0., 0., 0., ..., 0., 0., 0.],
...
Run Code Online (Sandbox Code Playgroud)

基本上什么也没有发生。实际上可以在这里显示图像吗?

小智 11

有一个扩展允许您在 python 调试期间查看图像/绘图。您只需在编辑器中选择图像变量,然后单击它附近就会出现灯泡。基本上,它只是将图像保存到临时位置,然后在侧面打开它。

免责声明:我是该扩展的作者。

https://marketplace.visualstudio.com/items?itemName=elazarcoh.simply-view-image-for-python-debugging


小智 0

或者直接使用这个方法。

from threading import Thread
import cv2

def showImage(img):

    def show(img):
        cv2.imshow(str(dt.datetime.today()), img)
        cv2.waitKey()

    Thread(target=show, args=[img]).start()

Run Code Online (Sandbox Code Playgroud)