# standalone_cv_resize_test.py import cv2 import numpy as np import sys # Crea un'immagine di test non quadrata height, width = 200, 600 img = np.zeros((height, width, 3), dtype=np.uint8) # Disegna qualcosa per vedere l'orientamento cv2.line(img, (0, 0), (width - 1, height - 1), (0, 255, 0), 2) cv2.rectangle( img, (width // 4, height // 4), (width * 3 // 4, height * 3 // 4), (0, 0, 255), 2 ) cv2.putText( img, f"{width}x{height}", (10, height - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1, ) window_name = "Resizable Keep Aspect Ratio Test" print(f"OpenCV Version: {cv2.__version__}") # print(cv2.getBuildInformation()) # Per dettagli sul backend GUI try: cv2.namedWindow(window_name, cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO) print(f"Created window '{window_name}' with flags WINDOW_NORMAL | WINDOW_KEEPRATIO") cv2.resizeWindow(window_name, width // 2, height // 2) # Dimensione iniziale print(f"Set initial window size to {width//2}x{height//2}") while True: cv2.imshow(window_name, img) key = cv2.waitKey(1) & 0xFF if key == ord("q") or key == 27: # Esci con 'q' o ESC break # Controlla se la finestra è stata chiusa try: # WND_PROP_VISIBLE è un modo comune, potrebbe variare leggermente if cv2.getWindowProperty(window_name, cv2.WND_PROP_VISIBLE) < 1: break except cv2.error: # Errore se la finestra non esiste più break except Exception as e: print(f"An error occurred: {e}") finally: print("Destroying all OpenCV windows.") cv2.destroyAllWindows() print("Exiting.")