import cv2 import ctypes import numpy as np from PIL import Image def load_image_utf8(image_path): """Load image with UTF-8 path support using PIL, then convert to OpenCV format""" try: # Use PIL to load image with UTF-8 support pil_image = Image.open(image_path) # Convert PIL image to OpenCV format (BGR) cv_image = cv2.cvtColor(np.array(pil_image), cv2.COLOR_RGB2BGR) return cv_image except Exception as e: raise ValueError(f"Could not load image file: {image_path} - {e}") def get_active_window_title(): """Get the title of the currently active window""" try: # Get handle to foreground window hwnd = ctypes.windll.user32.GetForegroundWindow() # Get window title length length = ctypes.windll.user32.GetWindowTextLengthW(hwnd) # Create buffer and get window title buffer = ctypes.create_unicode_buffer(length + 1) ctypes.windll.user32.GetWindowTextW(hwnd, buffer, length + 1) return buffer.value except: return ""