diff --git a/Makefile b/Makefile index 67699c8..c1458df 100644 --- a/Makefile +++ b/Makefile @@ -102,12 +102,12 @@ ocrd-test: tests/resources/2files/kant_aufklaerung_1784_0020.tif cp $< $(TMPDIR) ocrd workspace -d $(TMPDIR) init ocrd workspace -d $(TMPDIR) add -G OCR-D-IMG -g PHYS_0020 -i OCR-D-IMG_0020 $(= v0.7.0" + }, { "url": "https://zenodo.org/records/17295988/files/models_layout_v0_6_0.tar.gz?download=1", "name": "models_layout_v0_6_0", "type": "archive", "path_in_archive": "models_layout_v0_6_0", "size": 3525684179, - "description": "Models for layout detection, reading order detection, textline detection, page extraction, column classification, table detection, binarization, image enhancement", + "description": "Models for layout detection, reading order detection, textline detection, page extraction, column classification, table detection, binarization, image enhancement and OCR", "version_range": ">= v0.5.0" }, { diff --git a/src/eynollah/ocrd_cli_binarization.py b/src/eynollah/ocrd_cli_binarization.py index e5f85b1..a199e72 100644 --- a/src/eynollah/ocrd_cli_binarization.py +++ b/src/eynollah/ocrd_cli_binarization.py @@ -1,6 +1,8 @@ +from functools import cached_property from typing import Optional from PIL import Image +from frozendict import frozendict import numpy as np import cv2 from click import command @@ -9,6 +11,8 @@ from ocrd import Processor, OcrdPageResult, OcrdPageResultImage from ocrd_models.ocrd_page import OcrdPage, AlternativeImageType from ocrd.decorators import ocrd_cli_options, ocrd_cli_wrap_processor +from eynollah.model_zoo.model_zoo import EynollahModelZoo + from .sbb_binarize import SbbBinarizer @@ -25,7 +29,7 @@ class SbbBinarizeProcessor(Processor): # already employs GPU (without singleton process atm) max_workers = 1 - @property + @cached_property def executable(self): return 'ocrd-sbb-binarize' @@ -34,9 +38,9 @@ class SbbBinarizeProcessor(Processor): Set up the model prior to processing. """ # resolve relative path via OCR-D ResourceManager - assert isinstance(self.parameter, dict) - model_path = self.resolve_resource(self.parameter['model']) - self.binarizer = SbbBinarizer(model_dir=model_path, logger=self.logger) + assert isinstance(self.parameter, frozendict) + model_zoo = EynollahModelZoo(basedir=self.parameter['model']) + self.binarizer = SbbBinarizer(model_zoo=model_zoo, mode='single', logger=self.logger) def process_page_pcgts(self, *input_pcgts: Optional[OcrdPage], page_id: Optional[str] = None) -> OcrdPageResult: """ diff --git a/src/eynollah/processor.py b/src/eynollah/processor.py index 60c136c..6d80281 100644 --- a/src/eynollah/processor.py +++ b/src/eynollah/processor.py @@ -3,6 +3,8 @@ from typing import Optional from ocrd_models import OcrdPage from ocrd import OcrdPageResultImage, Processor, OcrdPageResult +from eynollah.model_zoo.model_zoo import EynollahModelZoo + from .eynollah import Eynollah, EynollahXmlWriter class EynollahProcessor(Processor): @@ -19,8 +21,9 @@ class EynollahProcessor(Processor): if self.parameter['textline_light'] != self.parameter['light_version']: raise ValueError("Error: You must set or unset both parameter 'textline_light' (to enable light textline detection), " "and parameter 'light_version' (faster+simpler method for main region detection and deskewing)") + model_zoo = EynollahModelZoo(basedir=self.parameter['models']) self.eynollah = Eynollah( - self.resolve_resource(self.parameter['models']), + model_zoo=model_zoo, allow_enhancement=self.parameter['allow_enhancement'], curved_line=self.parameter['curved_line'], right2left=self.parameter['right_to_left'],