OpenCV shows white screen when using cv2.setWindowProperty("Image", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

I’m using the following lines of code to set the image to fullscreen:

import cv2
cap = cv2.VideoCapture(0)

cv2.namedWindow("Image", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("Image", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

while cap.isOpened():
    success, image = cap.read()

    cv2.imshow("Image", image)

    if cv2.waitKey(5) & 0xFF == 27:
      break


cv2.destroyAllWindows()
cap.release()

However, the window shows a white screen.

When I commented out the line:

cv2.setWindowProperty("Image", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

The screen shows the webcam capture. I’ve tried reading an image file as well and yielded the same result. Would appreciate any help!

I’m on macOS Ventura 13.0.1 and using opencv-python version 4.7.0.68. Link to my stackoverflow question

for a start, you mixed up the constants, it should be:

cv2.namedWindow("Image", cv2.WINDOW_FULLSCREEN)
# if the former worked, the latter wont be nessecary !
#cv2.setWindowProperty("Image", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

Hi @berak, I switched the cv2.WND_PROP_FULLSCREEN to cv2.WINDOW_FULLSCREEN, but it doesn’t make the window fullscreen

I’ve also tried reading a single image file using the following code:

import cv2

img = cv2.imread('/path/to/image')
cv2.namedWindow("Image", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("Image", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

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

And the same thing happens: the window opens in fullscreen but the image shown is just white.

Would really appreciate any help!

afaik you can’t create a window to be full screen. you have to create it and then set the WND_PROP_FULLSCREEN to be WINDOW_FULLSCREEN

those enums are a mess