1 year ago

#338117

test-img

Igor Cantele

cv2 imshow() window immediately closes on WSL2

I am using opencv-python in wsl2, and I can't have any images displayed. If I try to run the code below, a window with the correct image and name will open, but will close immediately.
If I try to run the same doce on cmd on windows, it works perfectly.

img = cv2.imread(img_path)

if img is None:
    print('Error loading image')
    exit()

cv2.imshow("title", img)
cv2.waitKey(0)

I also have problem, on my WSL2, with cv2.VideoCapture(), that works on Windows but not on the virtual machine displaying this error:
[ WARN:0@2.573] global /io/opencv/modules/videoio/src/cap_v4l.cpp (889) open VIDEOIO(V4L2:/dev/video0): can't open camera by index

I am using:
Ubuntu 20.04 LTS
opencv-python: 4.5.5.64

I don't know if these 2 problems are related or if I have to add another question.

opencv

windows-subsystem-for-linux

v4l2

0 Answers

Your Answer

Accepted video resources