OpenCV shows a gray window

I am trying to display an image using OpenCV. I have the following code:

import cv2 img = cv2.imread('myimage.png', 0) # Reads a Gray-scale image img2 = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) cv2.imshow("window", img2) 

The window opens correctly, with the correct size, but it is gray - there is no image. The image is read correctly (looking at img and img2 in the debugger, I see the expected values, not just one hue).

Note. Obviously, I intend to do some image processing before the image is displayed, but first I need to see the image ...

+5
python opencv
source share
2 answers

OK, it turned out.

Turns out I needed to let OpenCV start event processing, this is not WM_PAINT event processing. Adding cv2.waitKey () fixed.

+13
source share

^^ Thank you, I had the same problem, and cv2.waitKey () fixed it for me too

0
source share

All Articles