mirror of
https://github.com/qurator-spk/eynollah.git
synced 2025-10-06 14:39:55 +02:00
move logging to CLI and make initialization optional
This commit is contained in:
parent
8ebba5ac04
commit
c64d102613
3 changed files with 52 additions and 16 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -5,3 +5,4 @@ models_eynollah*
|
|||
output.html
|
||||
/build
|
||||
/dist
|
||||
*.tif
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import sys
|
||||
import click
|
||||
import logging
|
||||
from ocrd_utils import initLogging, getLevelName, getLogger
|
||||
from eynollah.eynollah import Eynollah, Eynollah_ocr
|
||||
from eynollah.sbb_binarize import SbbBinarizer
|
||||
|
@ -241,15 +242,61 @@ def binarization(patches, model_dir, input_image, output_image, dir_in, dir_out)
|
|||
is_flag=True,
|
||||
help="if this parameter set to true, this tool will ignore layout detection and reading order. It means that textline detection will be done within printspace and contours of textline will be written in xml output file.",
|
||||
)
|
||||
# TODO move to top-level CLI context
|
||||
@click.option(
|
||||
"--log_level",
|
||||
"-l",
|
||||
type=click.Choice(['OFF', 'DEBUG', 'INFO', 'WARN', 'ERROR']),
|
||||
help="Override log level globally to this",
|
||||
help="Override 'eynollah' log level globally to this",
|
||||
)
|
||||
#
|
||||
@click.option(
|
||||
"--setup-logging",
|
||||
is_flag=True,
|
||||
help="Setup a basic console logger",
|
||||
)
|
||||
|
||||
def layout(image, out, overwrite, dir_in, model, save_images, save_layout, save_deskewed, save_all, extract_only_images, save_page, enable_plotting, allow_enhancement, curved_line, textline_light, full_layout, tables, right2left, input_binary, allow_scaling, headers_off, light_version, reading_order_machine_based, do_ocr, num_col_upper, num_col_lower, skip_layout_and_reading_order, ignore_page_extraction, log_level):
|
||||
initLogging()
|
||||
def layout(
|
||||
image,
|
||||
out,
|
||||
overwrite,
|
||||
dir_in,
|
||||
model,
|
||||
save_images,
|
||||
save_layout,
|
||||
save_deskewed,
|
||||
save_all,
|
||||
extract_only_images,
|
||||
save_page,
|
||||
enable_plotting,
|
||||
allow_enhancement,
|
||||
curved_line,
|
||||
textline_light,
|
||||
full_layout,
|
||||
tables,
|
||||
right2left,
|
||||
input_binary,
|
||||
allow_scaling,
|
||||
headers_off,
|
||||
light_version,
|
||||
reading_order_machine_based,
|
||||
do_ocr,
|
||||
num_col_upper,
|
||||
num_col_lower,
|
||||
skip_layout_and_reading_order,
|
||||
ignore_page_extraction,
|
||||
log_level,
|
||||
setup_logging
|
||||
):
|
||||
if setup_logging:
|
||||
console_handler = logging.StreamHandler(sys.stdout)
|
||||
console_handler.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter('%(message)s')
|
||||
console_handler.setFormatter(formatter)
|
||||
getLogger('eynollah').addHandler(console_handler)
|
||||
getLogger('eynollah').setLevel(logging.INFO)
|
||||
else:
|
||||
initLogging()
|
||||
if log_level:
|
||||
getLogger('eynollah').setLevel(getLevelName(log_level))
|
||||
assert enable_plotting or not save_layout, "Plotting with -sl also requires -ep"
|
||||
|
@ -273,7 +320,6 @@ def layout(image, out, overwrite, dir_in, model, save_images, save_layout, save_
|
|||
assert image or dir_in, "Either a single image -i or a dir_in -di is required"
|
||||
eynollah = Eynollah(
|
||||
model,
|
||||
logger=getLogger('eynollah'),
|
||||
dir_out=out,
|
||||
dir_of_cropped_images=save_images,
|
||||
extract_only_images=extract_only_images,
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
document layout analysis (segmentation) with output in PAGE-XML
|
||||
"""
|
||||
|
||||
from logging import Logger
|
||||
from difflib import SequenceMatcher as sq
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
import math
|
||||
|
@ -201,18 +200,8 @@ class Eynollah:
|
|||
num_col_upper : Optional[int] = None,
|
||||
num_col_lower : Optional[int] = None,
|
||||
skip_layout_and_reading_order : bool = False,
|
||||
logger : Optional[Logger] = None,
|
||||
):
|
||||
if logger:
|
||||
self.logger = logger
|
||||
else:
|
||||
self.logger = getLogger('eynollah')
|
||||
console_handler = logging.StreamHandler(sys.stdout)
|
||||
console_handler.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter('%(message)s')
|
||||
console_handler.setFormatter(formatter)
|
||||
self.logger.addHandler(console_handler)
|
||||
self.logger.setLevel(logging.INFO)
|
||||
self.logger = getLogger('eynollah')
|
||||
|
||||
if skip_layout_and_reading_order:
|
||||
textline_light = True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue