Files
duck-stain-yolo/app/ocr/factory.py

25 lines
739 B
Python

from __future__ import annotations
from typing import Any
from app.ocr.base import OcrEngine
from app.ocr.none import NoOcrEngine
from app.ocr.paddle import PaddleOcrEngine
from app.ocr.tesseract import TesseractOcrEngine
def create_ocr_engine(config: dict[str, Any]) -> OcrEngine:
ocr_cfg = config.get("ocr", {})
if not ocr_cfg.get("enabled", True):
return NoOcrEngine(ocr_cfg)
engine = str(ocr_cfg.get("engine", "tesseract")).lower()
if engine in {"none", "off", "disabled"}:
return NoOcrEngine(ocr_cfg)
if engine == "tesseract":
return TesseractOcrEngine(ocr_cfg)
if engine == "paddle":
return PaddleOcrEngine(ocr_cfg)
raise ValueError(f"Nieznany silnik OCR: {engine}")