Search code examples
opencvwindows-subsystem-for-linuxxming

openCV imshow in WSL using Xming


I am working on some video processing tasks and have been using opencv-python 4.2.0 as my go-to library. At first there was a problem with displaying video frames using the imshow function - I would only see a small black window, but I thought there was something wrong with my logic. I tried reproducing the problem in its simplest form - loading and displaying a static image:

import cv2
frame = imread("path/to/some/image.png")
print(frame.shape)
cv2.imshow('test', frame)

The output:

>>> (600, 600, 3)

opencv window

I have not had similar problems in this development environment before. I am developing under WSL (Ubuntu 16.04) and use Xming to display the program's window under Win10.


Solution

  • Image in window is updated when function waitKey() is executed - so you have to use it

    import cv2
    
    frame = cv2.imread("path/to/some/image.png")
    print(frame.shape)
    
    cv2.imshow('test', frame)
    cv2.waitKey(1)
    

    At least it resolves this problem on Linux Mint 19.3 based on Ubuntu 18.04