Try refactor everything into separate files

This commit is contained in:
2025-12-23 09:21:02 +01:00
parent 914ae29073
commit 4db35616af
5 changed files with 706 additions and 692 deletions

34
croppa/utils.py Normal file
View File

@@ -0,0 +1,34 @@
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 ""