0

Just a sample code

import cv2 as cv

img = cv.imread('book.jpg')
cv.imshow('img', img)

cv.waitKey(0)

As soon as the window opens, it closes, I am not able to even see the images properly.

I thought it was happening because I was using WSL (Linux) but the same thing is happening for me in windows too.

The same thing works fine on my friends computer. What could be the issue here?

Pragyan
  • 349
  • 2
  • 14

1 Answers1

0

So a workaround for this is to add destroyAllWindows task to the queue and delay it.

the new code would be then

import cv2 as cv

img = cv.imread('book.jpg')
cv.imshow('img', img)

cv.waitKey(0)
cv.destroyAllWindows()
cv.waitKey(1)

thanks to @AbhinavMathur comment

Pragyan
  • 349
  • 2
  • 14
  • 1
    "queue"? there is no queue. what are you talking about? -- `waitKey(0)`, as in the question's code, should have made the window responsive and available until some button is pressed or the window is explicitly closed. – Christoph Rackwitz Mar 06 '22 at 12:43