Provisionally add filters

This commit is contained in:
James R. Barlow
2019-05-25 16:23:39 -07:00
parent ed236e0c27
commit 24855045e1
3 changed files with 13 additions and 0 deletions
+3
View File
@@ -521,6 +521,9 @@ def create_ocr_image(image, page_context):
draw.rectangle(rect, fill=white)
im = pix.topil()
if options.filter_ocr_image:
im = options.filter_ocr_image(im)
del draw
# Pillow requires integer DPI
dpi = round(xres), round(yres)
+6
View File
@@ -113,10 +113,14 @@ def configure_logging(verbosity, progress_bar_friendly=True, manage_root_logger=
def create_options(*, input_file, output_file, **kwargs):
cmdline = []
filters = []
for arg, val in kwargs.items():
if val is None:
continue
if arg.startswith('filter') and callable(val):
filters.append((arg, val))
continue
cmd_style_arg = arg.replace('_', '-')
cmdline.append(f"--{cmd_style_arg}")
if isinstance(val, bool):
@@ -135,6 +139,8 @@ def create_options(*, input_file, output_file, **kwargs):
parser.api_mode = True
options = parser.parse_args(cmdline)
for keyword, function in filters:
setattr(options, keyword, function)
return options
+4
View File
@@ -466,6 +466,10 @@ advanced.add_argument(
help="Specify the location of the Tesseract user patterns file.",
)
filters = parser.add_argument_group("Filters", argparse.SUPPRESS)
filters.add_argument('--filter-ocr-image', help=argparse.SUPPRESS)
debugging = parser.add_argument_group(
"Debugging", "Arguments to help with troubleshooting and debugging"
)