Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Merge pull request #97 from qurator-spk/420-namespace-package" #108

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file removed qurator/__init__.py
Empty file.
1 change: 0 additions & 1 deletion qurator/eynollah/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

23 changes: 19 additions & 4 deletions qurator/eynollah/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,26 @@ 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))
pcgts = page_from_file(self.workspace.download_file(input_file))
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,
Expand All @@ -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()
kba marked this conversation as resolved.
Show resolved Hide resolved
file_id = make_file_id(input_file, self.output_file_grp)
pcgts.set_pcGtsId(file_id)
self.workspace.add_file(
Expand Down
2 changes: 1 addition & 1 deletion qurator/eynollah/utils/pil_cv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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')
Expand All @@ -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']
Expand Down