Files
2026-06-15 09:54:01 +09:00

38 lines
1.2 KiB
Python

# import config
#
# if config.OCR_ENGINE == "google":
# from utils.ocr_google import ocr_single, ocr_batch, get_vision_client
# else:
# from utils.ocr_paddle import ocr_single, ocr_batch
# def get_vision_client():
# return None # paddle은 client 불필요, 호환성 유지용
from utils.ocr_paddle import ocr_single as paddle_ocr_single, ocr_batch as paddle_ocr_batch
from utils.ocr_google import ocr_single as google_ocr_single, ocr_batch as google_ocr_batch, get_vision_client
import config
_google_client = None
def get_vision_client_cached():
global _google_client
if _google_client is None:
_google_client = get_vision_client()
return _google_client
def get_ocr_functions(engine: str):
if engine == "google":
return google_ocr_single, google_ocr_batch, get_vision_client_cached() # 캐싱된 클라이언트 사용
return paddle_ocr_single, paddle_ocr_batch, None
def ocr_single(image_path, client=None):
fn, _, c = get_ocr_functions(config.OCR_ENGINE)
return fn(image_path, c)
def ocr_batch(img_paths, client=None):
_, fn, c = get_ocr_functions(config.OCR_ENGINE)
return fn(img_paths, c)