|
|
@ -70,7 +70,7 @@ def gen_diff_report(gt_in, ocr_in, css_prefix, joiner, none, differences=False):
|
|
|
|
# support this, i.e. display for the one id produced
|
|
|
|
# support this, i.e. display for the one id produced
|
|
|
|
|
|
|
|
|
|
|
|
if differences:
|
|
|
|
if differences:
|
|
|
|
found_differences.append(f'{g} :: {o}')
|
|
|
|
found_differences.append(f"{g} :: {o}")
|
|
|
|
|
|
|
|
|
|
|
|
gtx += joiner + format_thing(g, css_classes, gt_id)
|
|
|
|
gtx += joiner + format_thing(g, css_classes, gt_id)
|
|
|
|
ocrx += joiner + format_thing(o, css_classes, ocr_id)
|
|
|
|
ocrx += joiner + format_thing(o, css_classes, ocr_id)
|
|
|
@ -82,14 +82,17 @@ def gen_diff_report(gt_in, ocr_in, css_prefix, joiner, none, differences=False):
|
|
|
|
|
|
|
|
|
|
|
|
found_differences = dict(Counter(elem for elem in found_differences))
|
|
|
|
found_differences = dict(Counter(elem for elem in found_differences))
|
|
|
|
|
|
|
|
|
|
|
|
return """
|
|
|
|
return (
|
|
|
|
|
|
|
|
"""
|
|
|
|
<div class="row">
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-6 gt">{}</div>
|
|
|
|
<div class="col-md-6 gt">{}</div>
|
|
|
|
<div class="col-md-6 ocr">{}</div>
|
|
|
|
<div class="col-md-6 ocr">{}</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
""".format(
|
|
|
|
""".format(
|
|
|
|
gtx, ocrx
|
|
|
|
gtx, ocrx
|
|
|
|
), found_differences
|
|
|
|
),
|
|
|
|
|
|
|
|
found_differences,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def json_float(value):
|
|
|
|
def json_float(value):
|
|
|
@ -105,8 +108,16 @@ def json_float(value):
|
|
|
|
return str(value)
|
|
|
|
return str(value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process(gt, ocr, report_prefix, reports_folder='.', *, metrics=True,
|
|
|
|
def process(
|
|
|
|
differences=False, textequiv_level="region"):
|
|
|
|
gt,
|
|
|
|
|
|
|
|
ocr,
|
|
|
|
|
|
|
|
report_prefix,
|
|
|
|
|
|
|
|
reports_folder=".",
|
|
|
|
|
|
|
|
*,
|
|
|
|
|
|
|
|
metrics=True,
|
|
|
|
|
|
|
|
differences=False,
|
|
|
|
|
|
|
|
textequiv_level="region",
|
|
|
|
|
|
|
|
):
|
|
|
|
"""Check OCR result against GT.
|
|
|
|
"""Check OCR result against GT.
|
|
|
|
|
|
|
|
|
|
|
|
The @click decorators change the signature of the decorated functions, so we keep this undecorated version and use
|
|
|
|
The @click decorators change the signature of the decorated functions, so we keep this undecorated version and use
|
|
|
@ -119,15 +130,19 @@ def process(gt, ocr, report_prefix, reports_folder='.', *, metrics=True,
|
|
|
|
cer, n_characters = character_error_rate_n(gt_text, ocr_text)
|
|
|
|
cer, n_characters = character_error_rate_n(gt_text, ocr_text)
|
|
|
|
wer, n_words = word_error_rate_n(gt_text, ocr_text)
|
|
|
|
wer, n_words = word_error_rate_n(gt_text, ocr_text)
|
|
|
|
|
|
|
|
|
|
|
|
char_diff_report, diff_c = gen_diff_report(gt_text, ocr_text, css_prefix="c",
|
|
|
|
char_diff_report, diff_c = gen_diff_report(
|
|
|
|
joiner="",
|
|
|
|
gt_text, ocr_text, css_prefix="c", joiner="", none="·", differences=differences
|
|
|
|
none="·", differences=differences)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
gt_words = words_normalized(gt_text)
|
|
|
|
gt_words = words_normalized(gt_text)
|
|
|
|
ocr_words = words_normalized(ocr_text)
|
|
|
|
ocr_words = words_normalized(ocr_text)
|
|
|
|
word_diff_report, diff_w = gen_diff_report(
|
|
|
|
word_diff_report, diff_w = gen_diff_report(
|
|
|
|
gt_words, ocr_words, css_prefix="w", joiner=" ", none="⋯",
|
|
|
|
gt_words,
|
|
|
|
differences=differences
|
|
|
|
ocr_words,
|
|
|
|
|
|
|
|
css_prefix="w",
|
|
|
|
|
|
|
|
joiner=" ",
|
|
|
|
|
|
|
|
none="⋯",
|
|
|
|
|
|
|
|
differences=differences,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
env = Environment(
|
|
|
|
env = Environment(
|
|
|
@ -162,19 +177,23 @@ def process(gt, ocr, report_prefix, reports_folder='.', *, metrics=True,
|
|
|
|
).dump(out_fn)
|
|
|
|
).dump(out_fn)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def process_dir(gt, ocr, report_prefix, reports_folder, metrics, differences,
|
|
|
|
def process_dir(
|
|
|
|
textequiv_level):
|
|
|
|
gt, ocr, report_prefix, reports_folder, metrics, differences, textequiv_level
|
|
|
|
|
|
|
|
):
|
|
|
|
for gt_file in os.listdir(gt):
|
|
|
|
for gt_file in os.listdir(gt):
|
|
|
|
gt_file_path = os.path.join(gt, gt_file)
|
|
|
|
gt_file_path = os.path.join(gt, gt_file)
|
|
|
|
ocr_file_path = os.path.join(ocr, gt_file)
|
|
|
|
ocr_file_path = os.path.join(ocr, gt_file)
|
|
|
|
|
|
|
|
|
|
|
|
if os.path.isfile(gt_file_path) and os.path.isfile(ocr_file_path):
|
|
|
|
if os.path.isfile(gt_file_path) and os.path.isfile(ocr_file_path):
|
|
|
|
process(gt_file_path, ocr_file_path,
|
|
|
|
process(
|
|
|
|
|
|
|
|
gt_file_path,
|
|
|
|
|
|
|
|
ocr_file_path,
|
|
|
|
f"{gt_file}-{report_prefix}",
|
|
|
|
f"{gt_file}-{report_prefix}",
|
|
|
|
reports_folder=reports_folder,
|
|
|
|
reports_folder=reports_folder,
|
|
|
|
metrics=metrics,
|
|
|
|
metrics=metrics,
|
|
|
|
differences=differences,
|
|
|
|
differences=differences,
|
|
|
|
textequiv_level=textequiv_level)
|
|
|
|
textequiv_level=textequiv_level,
|
|
|
|
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
print("Skipping {0} and {1}".format(gt_file_path, ocr_file_path))
|
|
|
|
print("Skipping {0} and {1}".format(gt_file_path, ocr_file_path))
|
|
|
|
|
|
|
|
|
|
|
@ -190,7 +209,7 @@ def process_dir(gt, ocr, report_prefix, reports_folder, metrics, differences,
|
|
|
|
@click.option(
|
|
|
|
@click.option(
|
|
|
|
"--differences",
|
|
|
|
"--differences",
|
|
|
|
default=False,
|
|
|
|
default=False,
|
|
|
|
help="Enable reporting character and word level differences"
|
|
|
|
help="Enable reporting character and word level differences",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@click.option(
|
|
|
|
@click.option(
|
|
|
|
"--textequiv-level",
|
|
|
|
"--textequiv-level",
|
|
|
@ -199,8 +218,16 @@ def process_dir(gt, ocr, report_prefix, reports_folder, metrics, differences,
|
|
|
|
metavar="LEVEL",
|
|
|
|
metavar="LEVEL",
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@click.option("--progress", default=False, is_flag=True, help="Show progress bar")
|
|
|
|
@click.option("--progress", default=False, is_flag=True, help="Show progress bar")
|
|
|
|
def main(gt, ocr, report_prefix, reports_folder, metrics, differences, textequiv_level,
|
|
|
|
def main(
|
|
|
|
progress):
|
|
|
|
gt,
|
|
|
|
|
|
|
|
ocr,
|
|
|
|
|
|
|
|
report_prefix,
|
|
|
|
|
|
|
|
reports_folder,
|
|
|
|
|
|
|
|
metrics,
|
|
|
|
|
|
|
|
differences,
|
|
|
|
|
|
|
|
textequiv_level,
|
|
|
|
|
|
|
|
progress,
|
|
|
|
|
|
|
|
):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Compare the PAGE/ALTO/text document GT against the document OCR.
|
|
|
|
Compare the PAGE/ALTO/text document GT against the document OCR.
|
|
|
|
|
|
|
|
|
|
|
@ -228,11 +255,25 @@ def main(gt, ocr, report_prefix, reports_folder, metrics, differences, textequiv
|
|
|
|
"OCR must be a directory if GT is a directory", param_hint="ocr"
|
|
|
|
"OCR must be a directory if GT is a directory", param_hint="ocr"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
process_dir(gt, ocr, report_prefix, reports_folder, metrics,
|
|
|
|
process_dir(
|
|
|
|
differences, textequiv_level)
|
|
|
|
gt,
|
|
|
|
|
|
|
|
ocr,
|
|
|
|
|
|
|
|
report_prefix,
|
|
|
|
|
|
|
|
reports_folder,
|
|
|
|
|
|
|
|
metrics,
|
|
|
|
|
|
|
|
differences,
|
|
|
|
|
|
|
|
textequiv_level,
|
|
|
|
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
process(gt, ocr, report_prefix, reports_folder, metrics=metrics,
|
|
|
|
process(
|
|
|
|
differences=differences, textequiv_level=textequiv_level)
|
|
|
|
gt,
|
|
|
|
|
|
|
|
ocr,
|
|
|
|
|
|
|
|
report_prefix,
|
|
|
|
|
|
|
|
reports_folder,
|
|
|
|
|
|
|
|
metrics=metrics,
|
|
|
|
|
|
|
|
differences=differences,
|
|
|
|
|
|
|
|
textequiv_level=textequiv_level,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
if __name__ == "__main__":
|
|
|
|