Provisionally add filters
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user