mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-06-09 12:19:54 +02:00
pep8-e302: two blank lines between functions
This commit is contained in:
parent
caf0fbe90f
commit
fa7bb63481
11 changed files with 25 additions and 0 deletions
|
@ -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()
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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__)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue