From fa7bb634812cc3d70d6528feb5a24ac9e34b8f79 Mon Sep 17 00:00:00 2001 From: cneud <952378+cneud@users.noreply.github.com> Date: Tue, 25 Mar 2025 22:36:22 +0100 Subject: [PATCH] pep8-e302: two blank lines between functions --- src/eynollah/ocrd_cli.py | 2 ++ src/eynollah/ocrd_cli_binarization.py | 4 ++++ src/eynollah/plot.py | 1 + src/eynollah/processor.py | 1 + src/eynollah/sbb_binarize.py | 2 ++ src/eynollah/utils/marginals.py | 1 + src/eynollah/utils/pil_cv2.py | 3 +++ src/eynollah/utils/resize.py | 1 + src/eynollah/utils/xml.py | 3 +++ tests/base.py | 3 +++ tests/test_counter.py | 4 ++++ 11 files changed, 25 insertions(+) diff --git a/src/eynollah/ocrd_cli.py b/src/eynollah/ocrd_cli.py index 8929927..499661b 100644 --- a/src/eynollah/ocrd_cli.py +++ b/src/eynollah/ocrd_cli.py @@ -2,10 +2,12 @@ from .processor import EynollahProcessor from click import command from ocrd.decorators import ocrd_cli_options, ocrd_cli_wrap_processor + @command() @ocrd_cli_options def main(*args, **kwargs): return ocrd_cli_wrap_processor(EynollahProcessor, *args, **kwargs) + if __name__ == '__main__': main() diff --git a/src/eynollah/ocrd_cli_binarization.py b/src/eynollah/ocrd_cli_binarization.py index 6a8bbdc..dfdb7b6 100644 --- a/src/eynollah/ocrd_cli_binarization.py +++ b/src/eynollah/ocrd_cli_binarization.py @@ -25,15 +25,18 @@ from .sbb_binarize import SbbBinarizer OCRD_TOOL = loads(resource_string(__name__, 'ocrd-tool-binarization.json').decode('utf8')) TOOL = 'ocrd-sbb-binarize' + def cv2pil(img): return Image.fromarray(img.astype('uint8')) + def pil2cv(img): # from ocrd/workspace.py color_conversion = cv2.COLOR_GRAY2BGR if img.mode in ('1', 'L') else cv2.COLOR_RGB2BGR pil_as_np_array = np.array(img).astype('uint8') if img.mode == '1' else np.array(img) return cv2.cvtColor(pil_as_np_array, color_conversion) + class SbbBinarizeProcessor(Processor): def __init__(self, *args, **kwargs): @@ -152,6 +155,7 @@ class SbbBinarizeProcessor(Processor): local_filename=join(self.output_file_grp, file_id + '.xml'), content=to_xml(pcgts)) + @command() @ocrd_cli_options def cli(*args, **kwargs): diff --git a/src/eynollah/plot.py b/src/eynollah/plot.py index 9d7eaf7..11b11a5 100644 --- a/src/eynollah/plot.py +++ b/src/eynollah/plot.py @@ -9,6 +9,7 @@ from .utils import crop_image_inside_box from .utils.rotate import rotate_image_different from .utils.resize import resize_image + class EynollahPlotter: """ Class collecting all the plotting and image writing methods diff --git a/src/eynollah/processor.py b/src/eynollah/processor.py index 4eced21..9400818 100644 --- a/src/eynollah/processor.py +++ b/src/eynollah/processor.py @@ -22,6 +22,7 @@ from .utils.pil_cv2 import pil2cv OCRD_TOOL = loads(resource_string(__name__, 'ocrd-tool.json').decode('utf8')) + class EynollahProcessor(Processor): def __init__(self, *args, **kwargs): diff --git a/src/eynollah/sbb_binarize.py b/src/eynollah/sbb_binarize.py index 36e9ab0..6c9acf1 100644 --- a/src/eynollah/sbb_binarize.py +++ b/src/eynollah/sbb_binarize.py @@ -23,9 +23,11 @@ sys.stderr = stderr import logging + def resize_image(img_in, input_height, input_width): return cv2.resize(img_in, (input_width, input_height), interpolation=cv2.INTER_NEAREST) + class SbbBinarizer: def __init__(self, model_dir, logger=None): diff --git a/src/eynollah/utils/marginals.py b/src/eynollah/utils/marginals.py index cceb70b..96c512c 100644 --- a/src/eynollah/utils/marginals.py +++ b/src/eynollah/utils/marginals.py @@ -6,6 +6,7 @@ from .contour import find_new_features_of_contours, return_contours_of_intereste from .resize import resize_image from .rotate import rotate_image + def get_marginals(text_with_lines, text_regions, num_col, slope_deskew, light_version=False, kernel=None): mask_marginals=np.zeros((text_with_lines.shape[0],text_with_lines.shape[1])) mask_marginals=mask_marginals.astype(np.uint8) diff --git a/src/eynollah/utils/pil_cv2.py b/src/eynollah/utils/pil_cv2.py index 83ae47d..cc128e4 100644 --- a/src/eynollah/utils/pil_cv2.py +++ b/src/eynollah/utils/pil_cv2.py @@ -5,15 +5,18 @@ from cv2 import COLOR_GRAY2BGR, COLOR_RGB2BGR, COLOR_BGR2RGB, cvtColor, imread # from sbb_binarization + def cv2pil(img): return Image.fromarray(np.array(cvtColor(img, COLOR_BGR2RGB))) + def pil2cv(img): # from ocrd/workspace.py color_conversion = COLOR_GRAY2BGR if img.mode in ('1', 'L') else COLOR_RGB2BGR pil_as_np_array = np.array(img).astype('uint8') if img.mode == '1' else np.array(img) return cvtColor(pil_as_np_array, color_conversion) + def check_dpi(img): try: if isinstance(img, Image.Image): diff --git a/src/eynollah/utils/resize.py b/src/eynollah/utils/resize.py index fdc49ec..8c09b04 100644 --- a/src/eynollah/utils/resize.py +++ b/src/eynollah/utils/resize.py @@ -1,4 +1,5 @@ import cv2 + def resize_image(img_in, input_height, input_width): return cv2.resize(img_in, (input_width, input_height), interpolation=cv2.INTER_NEAREST) diff --git a/src/eynollah/utils/xml.py b/src/eynollah/utils/xml.py index bd95702..f730840 100644 --- a/src/eynollah/utils/xml.py +++ b/src/eynollah/utils/xml.py @@ -29,6 +29,7 @@ from ocrd_models.ocrd_page import ( to_xml) + def create_page_xml(imageFilename, height, width): now = datetime.now() pcgts = PcGtsType( @@ -46,6 +47,7 @@ def create_page_xml(imageFilename, height, width): )) return pcgts + def xml_reading_order(page, order_of_texts, id_of_marginalia): region_order = ReadingOrderType() og = OrderedGroupType(id="ro357564684568544579089") @@ -59,6 +61,7 @@ def xml_reading_order(page, order_of_texts, id_of_marginalia): og.add_RegionRefIndexed(RegionRefIndexedType(index=str(region_counter.get('region')), regionRef=id_marginal)) region_counter.inc('region') + def order_and_id_of_texts(found_polygons_text_region, found_polygons_text_region_h, matrix_of_orders, indexes_sorted, index_of_types, kind_of_texts, ref_point): indexes_sorted = np.array(indexes_sorted) index_of_types = np.array(index_of_types) diff --git a/tests/base.py b/tests/base.py index 9de35ef..4ff508e 100644 --- a/tests/base.py +++ b/tests/base.py @@ -10,12 +10,14 @@ from unittest import TestCase as VanillaTestCase, skip, main as unittests_main import pytest from ocrd_utils import disableLogging, initLogging + def main(fn=None): if fn: sys.exit(pytest.main([fn])) else: unittests_main() + class TestCase(VanillaTestCase): @classmethod @@ -26,6 +28,7 @@ class TestCase(VanillaTestCase): disableLogging() initLogging() + class CapturingTestCase(TestCase): """ A TestCase that needs to capture stderr/stdout and invoke click CLI. diff --git a/tests/test_counter.py b/tests/test_counter.py index 42bf074..4b40ff2 100644 --- a/tests/test_counter.py +++ b/tests/test_counter.py @@ -1,6 +1,7 @@ from tests.base import main from eynollah.utils.counter import EynollahIdCounter + def test_counter_string(): c = EynollahIdCounter() assert c.next_region_id == 'region_0001' @@ -11,6 +12,7 @@ def test_counter_string(): assert c.region_id(999) == 'region_0999' assert c.line_id(999, 888) == 'region_0999_line_0888' + def test_counter_init(): c = EynollahIdCounter(region_idx=2) assert c.get('region') == 2 @@ -19,6 +21,7 @@ def test_counter_init(): c.reset() assert c.get('region') == 2 + def test_counter_methods(): c = EynollahIdCounter() assert c.get('region') == 0 @@ -29,5 +32,6 @@ def test_counter_methods(): c.inc('region', -9) assert c.get('region') == 1 + if __name__ == '__main__': main(__file__)