diff --git a/qurator/__init__.py b/qurator/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/qurator/eynollah/__init__.py b/qurator/eynollah/__init__.py index 8b13789..e69de29 100644 --- a/qurator/eynollah/__init__.py +++ b/qurator/eynollah/__init__.py @@ -1 +0,0 @@ - diff --git a/qurator/eynollah/processor.py b/qurator/eynollah/processor.py index ccec456..bf76295 100644 --- a/qurator/eynollah/processor.py +++ b/qurator/eynollah/processor.py @@ -33,6 +33,7 @@ def process(self): LOG = getLogger('eynollah') assert_file_grp_cardinality(self.input_file_grp, 1) assert_file_grp_cardinality(self.output_file_grp, 1) + models = None for n, input_file in enumerate(self.input_files): page_id = input_file.pageId or input_file.ID LOG.info("INPUT FILE %s (%d/%d) ", page_id, n + 1, len(self.input_files)) @@ -40,9 +41,18 @@ def process(self): LOG.debug('width %s height %s', pcgts.get_Page().imageWidth, pcgts.get_Page().imageHeight) self.add_metadata(pcgts) page = pcgts.get_Page() + # if not('://' in page.imageFilename): + # image_filename = next(self.workspace.mets.find_files(local_filename=page.imageFilename)).local_filename + # else: + # # could be a URL with file:// or truly remote + # image_filename = self.workspace.download_file(next(self.workspace.mets.find_files(url=page.imageFilename))).local_filename # XXX loses DPI information - # page_image, _, _ = self.workspace.image_from_page(page, page_id, feature_filter='binarized') - image_filename = self.workspace.download_file(next(self.workspace.mets.find_files(url=page.imageFilename))).local_filename + page_image, _, _ = self.workspace.image_from_page( + page, page_id, + # avoid any features that would change the coordinate system: cropped,deskewed + # (the PAGE builder merely adds regions, so afterwards we would not know which to transform) + # also avoid binarization as models usually fare better on grayscale/RGB + feature_filter='cropped,deskewed,binarized') eynollah_kwargs = { 'dir_models': self.resolve_resource(self.parameter['models']), 'allow_enhancement': False, @@ -54,9 +64,14 @@ def process(self): 'override_dpi': self.parameter['dpi'], 'logger': LOG, 'pcgts': pcgts, - 'image_filename': image_filename + 'image_filename': page.imageFilename, + 'image_pil': page_image } - Eynollah(**eynollah_kwargs).run() + eynollah = Eynollah(**eynollah_kwargs) + if models is not None: + # reuse loaded models from previous page + eynollah.models = models + pcgts = eynollah.run() file_id = make_file_id(input_file, self.output_file_grp) pcgts.set_pcGtsId(file_id) self.workspace.add_file( diff --git a/qurator/eynollah/utils/pil_cv2.py b/qurator/eynollah/utils/pil_cv2.py index 20dc22f..83ae47d 100644 --- a/qurator/eynollah/utils/pil_cv2.py +++ b/qurator/eynollah/utils/pil_cv2.py @@ -16,7 +16,7 @@ def pil2cv(img): def check_dpi(img): try: - if isinstance(img, Image.__class__): + if isinstance(img, Image.Image): pil_image = img elif isinstance(img, str): pil_image = Image.open(img) diff --git a/setup.py b/setup.py index 807eae7..af8a321 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,4 @@ -from setuptools import find_namespace_packages, find_packages, setup +from setuptools import setup, find_namespace_packages from json import load install_requires = open('requirements.txt').read().split('\n') @@ -13,7 +13,7 @@ author='Vahid Rezanezhad', url='https://github.com/qurator-spk/eynollah', license='Apache License 2.0', - packages=find_packages(exclude=['tests']), + packages=find_namespace_packages(include=['qurator']), install_requires=install_requires, package_data={ '': ['*.json']