diff --git a/Data/Modules/data_collector.py b/Data/Modules/data_collector.py index 50ef5fd..713e7bf 100644 --- a/Data/Modules/data_collector.py +++ b/Data/Modules/data_collector.py @@ -20,10 +20,15 @@ from PyQt5.QtCore import QRect, QPoint, Qt, QMutex, QTimer from PyQt5.QtGui import QPainter, QPen, QColor, QFont # Initialize EasyOCR with CUDA support -reader_cpu = easyocr.Reader(['en'], gpu=False) -reader_gpu = easyocr.Reader(['en'], gpu=True if torch.cuda.is_available() else False) +reader_cpu = None +reader_gpu = None -pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe" +def initialize_ocr_engines(): + global reader_cpu, reader_gpu + reader_cpu = easyocr.Reader(['en'], gpu=False) + reader_gpu = easyocr.Reader(['en'], gpu=True if torch.cuda.is_available() else False) + +pytesseract.pytesseract.tesseract_cmd = r"C:\\Program Files\\Tesseract-OCR\\tesseract.exe" DEFAULT_WIDTH = 180 DEFAULT_HEIGHT = 130 @@ -59,9 +64,8 @@ def create_ocr_region(region_id, x=250, y=50, w=DEFAULT_WIDTH, h=DEFAULT_HEIGHT, Creates an OCR region with a visible, resizable box on the screen. Allows setting custom color (RGB) and line thickness. """ - _ensure_qapplication() - + collector_mutex.lock() if region_id in regions: collector_mutex.unlock() @@ -73,7 +77,6 @@ def create_ocr_region(region_id, x=250, y=50, w=DEFAULT_WIDTH, h=DEFAULT_HEIGHT, } collector_mutex.unlock() - def get_raw_text(region_id): collector_mutex.lock() if region_id not in regions: @@ -83,12 +86,11 @@ def get_raw_text(region_id): collector_mutex.unlock() return text - def start_collector(): + initialize_ocr_engines() t = threading.Thread(target=_update_ocr_loop, daemon=True) t.start() - def _update_ocr_loop(): while True: collector_mutex.lock() @@ -112,7 +114,6 @@ def _update_ocr_loop(): time.sleep(0.7) - def _preprocess_image(image): gray = image.convert("L") scaled = gray.resize((gray.width * 3, gray.height * 3))