From 6683bb7e2f166a8b2a01a6ff5cb41c493fbd0f77 Mon Sep 17 00:00:00 2001 From: Prince Kumar Date: Wed, 9 Oct 2024 00:14:33 +0530 Subject: [PATCH] Fixed [Environment] OpenCV NULL guiReceiver error during pre-commit testing . added a check to see if a window is available, or create one if its not. --- src/utils/interaction.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/utils/interaction.py b/src/utils/interaction.py index 1036f5b3..aba5e754 100644 --- a/src/utils/interaction.py +++ b/src/utils/interaction.py @@ -38,6 +38,9 @@ def show(name, origin, pause=1, resize=False, reset_pos=None, config=None): else: img = origin + if not is_window_available(name): + cv2.namedWindow(name) + cv2.imshow(name, img) if reset_pos: @@ -92,3 +95,13 @@ def wait_q(): while cv2.waitKey(1) & 0xFF not in [ord("q"), esc_key]: pass cv2.destroyAllWindows() + + +def is_window_available(name: str) -> bool: + """Checks if a window is available""" + try: + cv2.getWindowProperty(name, cv2.WND_PROP_VISIBLE) + return True + except Exception as e: + print(e) + return False