How to expand image to fullscreen with Imshow() method

Hi and happy new year to all,

I have a small question regarding the imshow() method.
I use the fullscreen property to expand the window to all the screen, but the displayed picture in this window still keep its original dimension. I would like the displayed image to expand on all the avalaible space even if ratio is not respected. How can I do that ? Following is my code.
Thanks for you help

cv2.namedWindow(“image”, cv2.WND_PROP_FULLSCREEN)
key = cv2.waitKey(1)
cv2.imshow(“image”, image)

add WINDOW_NORMAL to the creation flags

@crackwitz, thanks a lot for your reply, but not sure that I do it well, because nothing happen.
Following is what I did :
cv2.namedWindow(“image”, cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty(“image”, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_NORMAL)
key = cv2.waitKey(1)
cv2.imshow(“image”, image)

Window is fullscreen, but the displayed image inside still occupied partially the window rather than using the full space of the window.

wrong place. I said creation flags. that means namedWindow, not property setting call

I also test this option previously and not better :frowning:
cv2.namedWindow(“image”, cv2.WINDOW_NORMAL)
cv2.setWindowProperty(“image”, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
key = cv2.waitKey(1)
cv2.imshow(“image”, image)

what does this look like when you run it? (picture)

This is what it looks like, nice picture :slight_smile:

As you can see the window is fullscreen, however displayed image does not fill the window, it keeps its original size.

why are you calling waitkey with ONE MILLISECOND of wait time, AND ONLY THEN call imshow?

im = cv.imread(cv.samples.findFile("lena.jpg"))
cv.namedWindow("foo", cv.WINDOW_NORMAL)
cv.setWindowProperty("foo", cv.WND_PROP_FULLSCREEN, cv.WINDOW_FULLSCREEN)
cv.imshow("foo", im)

this gives me a full-screen stretched Lena.

Thanks @crackwitz, removing the 1 millisecond in the waitKey method solve partially the problem. It displays the window fullscreen and the picture spread as large as possible keeping ratio.
However, my program loop over several pictures (frame from a camera) and after the first frame displayed, it freezes and does not display the other frames. If I put 1 millisecond in the waitKey method, then it does not freeze anymore, but then the frame does not spread over the window… Not really understand the impact of the waitKey method…

put it AFTER the imshow

Yes that’s exactly what I did, putting waitKey after imshow. But if I call waitKey method without parameter I cannot display the next frame, it is frozen. The only thing which is different with your code I do not destroy the window after waitKey, because I need it for the next frame.

Ok, understand. Calling waitKey without parameter means that it will indefinitly wait a key to be pressed to continue. It is not frozen. However I need the next frame to be displayed without waiting for a key to be pressed.

Arg… found the issue. imshow resize the image corresponding to property set after few millisecond. But if I loop over several frames and my waitKey is waiting for less time than imshow takes to resize the frame, then it always displays the frame not resized. Using waitKey(50) gives enough time for imshow to resize correctly the picture before displayng the next frame… This is treacky !!

Last question @crackwitz, as you can see on my screenshot, the picture does not stretch on all the window. But I would like to fullfill the entire window without take care of ratio. Any idea. Thanks again for your patience and great help !!

additionally pass WINDOW_FREERATIO to namedWindow

the gui backends differ between platforms. some maintain aspect ratio by default, some don’t.

Thanks a lot Christoph, I have tried WINDOW_FREERATIO but not better. Do you know if it is possible to define the background of the window to black to do not have the grey band on each side of the picture ?

setting the background color is probably not possible.

if you need more than imshow can give you, you should use a GUI toolkit like Tkinter or Qt or GTK.

Well noted, thanks again for your great help and best wishes for this new year.