Solve the problem that opencv and matplotlib cannot display images directly when using VScode remote server


Problem description : When connecting to the server through SSH in VSCode, images cannot be displayed using cv2.imshow or plt.show().

1. This solution has VScode and MobaXterm installed locally by default.

And VScode and MobaXterm can ssh to the remote server

2. On the server side

Insert image description here

export DISPLAY="172.22.205.229:0.0"

3. Install MobaXterm locally

Insert image description here
Parameter Description:
Insert image description here

4. Test

Keep MobaXterm open and run xclock in VSCode, and a clock will be displayed.
Insert image description here

5. Opencv display test (MobaXterm needs to be kept open during the test)

import cv2 as cv
 
src = cv.imread("LaSOT/LaSOTBenchmark/bicycle/bicycle-1/img/00000001.jpg")
cv.namedWindow("test",0)
cv.imshow("test",src)
cv.waitKey(0)
cv.destroyAllWindows()

Insert image description here

6. matplotlib display test (MobaXterm needs to be kept open during the test)

import matplotlib.pyplot as plt
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
ax = plt.axes(projection='3d')
ax.scatter(np.random.rand(10),np.random.rand(10),np.random.rand(10))
plt.show()

Insert image description here

Guess you like

Origin blog.csdn.net/guoqingru0311/article/details/132140728