[Python] OpenCV update changes behaviour, getWindowProperty and waitKey

Discussão em 'Python' iniciado por Stack, Fevereiro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I took back a python project that uses openCV to show images in a separate window. The project is in Python 3.8 and I am upgrading it to Python 3.12. I also updating openCV from version 4.4.0.46 to version 4.11.0.86. The project consist of a local web server with Flask that can do various operations depending on the API call.

    One API call result in the following set of lines of code:

    window_name = "projector"
    if cv2.getWindowProperty(window_name, 0) >= 0:
    cv2.imshow(window_name, full_screen_frame)
    else:
    cv2.namedWindow(window_name, cv2.WND_PROP_FULLSCREEN)
    cv2.moveWindow(window_name, window_move[0], window_move[1])
    cv2.setWindowProperty(window_name, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

    cv2.imshow(window_name, full_screen_frame)
    cv2.waitKey()


    In the 4.4 version, I can call this API multiple times and everything works fine.

    In the 4.11 version I have an exception on the getWindowProperty call. I fixed it using a try/except clause and the image shows just fine. But when the API il called again, the code stop executing a the getWindowProperty line, as if the waitKey is blocking the execution.

    I have another API that closes the window with cv2.destroyAllWindows() but it also frezze on that line with the version 4.11

    I don’t understand this change of behaviour. Do you know how to solve this issue? Thank you

    Continue reading...

Compartilhe esta Página