Implement OCR engine architecture with base, factory, and specific engines

This commit is contained in:
2026-05-08 07:08:48 +02:00
parent d117be5eec
commit 061ebf9978
7 changed files with 460 additions and 0 deletions

24
app/ocr/factory.py Normal file
View File

@@ -0,0 +1,24 @@
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}")