Optimized OCR Engine Initialization to only take place after a node that uses OCR is created.
This commit is contained in:
parent
e56b5a860f
commit
7d39baad90
@ -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 = None
|
||||
reader_gpu = None
|
||||
|
||||
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"
|
||||
pytesseract.pytesseract.tesseract_cmd = r"C:\\Program Files\\Tesseract-OCR\\tesseract.exe"
|
||||
|
||||
DEFAULT_WIDTH = 180
|
||||
DEFAULT_HEIGHT = 130
|
||||
@ -59,7 +64,6 @@ 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()
|
||||
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user