Merge in RR/cv-analysis from add_table_parsing_fixtures to master
Squashed commit of the following:
commit cfc89b421b61082c8e92e1971c9d0bf4490fa07e
Merge: a7ecb05 73c66a8
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Mon Jul 11 12:19:01 2022 +0200
Merge branch 'master' of ssh://git.iqser.com:2222/rr/cv-analysis into add_table_parsing_fixtures
commit a7ecb05b7d8327f0c7429180f63a380b61b06bc3
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Mon Jul 11 12:02:07 2022 +0200
refactor
commit 466f217e5a9ee5c54fd38c6acd28d54fc38ff9bb
Author: llocarnini <lillian.locarnini@iqser.com>
Date: Mon Jul 11 10:24:14 2022 +0200
deleted unused imports and unused lines of code
commit c58955c8658d0631cdd1c24c8556d399e3fd9990
Author: llocarnini <lillian.locarnini@iqser.com>
Date: Mon Jul 11 10:16:01 2022 +0200
black reformatted files
commit f8bcb10a00ff7f0da49b80c1609b17997411985a
Author: llocarnini <lillian.locarnini@iqser.com>
Date: Tue Jul 5 15:15:00 2022 +0200
reformat files
commit 432e8a569fd70bd0745ce0549c2bfd2f2e907763
Author: llocarnini <lillian.locarnini@iqser.com>
Date: Tue Jul 5 15:08:22 2022 +0200
added better test for generic pages with table WIP as thicker lines create inconsistent results.
added test for patchy tables which does not work yet
commit 2aac9ebf5c76bd963f8c136fe5dd4c2d7681b469
Author: llocarnini <lillian.locarnini@iqser.com>
Date: Mon Jul 4 16:56:29 2022 +0200
added new fixtures for table_parsing_test.py
commit 37606cac0301b13e99be2c16d95867477f29e7c4
Author: llocarnini <lillian.locarnini@iqser.com>
Date: Fri Jul 1 16:02:44 2022 +0200
added separate file for table parsing fixtures, where fixtures for generic tables were added. WIP tests for generic table fixtures
58 lines
2.3 KiB
Python
58 lines
2.3 KiB
Python
import cv2
|
|
import numpy as np
|
|
import pytest
|
|
|
|
from cv_analysis.figure_detection.text import (
|
|
remove_primary_text_regions,
|
|
apply_threshold_to_image,
|
|
)
|
|
from cv_analysis.utils.display import show_mpl
|
|
from test.utils.utils import powerset
|
|
|
|
|
|
@pytest.mark.parametrize("error_tolerance", [0.07])
|
|
@pytest.mark.parametrize("background_color", [255, 220])
|
|
class TestFindPrimaryTextRegions:
|
|
def test_blank_page_stays_blank(self, background, error_tolerance):
|
|
result_page = remove_primary_text_regions(background)
|
|
|
|
np.testing.assert_equal(result_page, apply_threshold_to_image(background))
|
|
|
|
@pytest.mark.parametrize("image_size", [(200, 200), (500, 500), (800, 800)])
|
|
@pytest.mark.parametrize("n_images", [1, 2])
|
|
def test_page_without_text_keeps_images(self, page_with_images, error_tolerance):
|
|
result_page = remove_primary_text_regions(page_with_images)
|
|
np.testing.assert_equal(result_page, apply_threshold_to_image(page_with_images))
|
|
|
|
@pytest.mark.parametrize("font_scale", [1, 1.5, 2])
|
|
@pytest.mark.parametrize(
|
|
"font_style", [cv2.FONT_HERSHEY_SIMPLEX, cv2.FONT_HERSHEY_COMPLEX]
|
|
)
|
|
@pytest.mark.parametrize("text_types", powerset(["body", "header", "caption"]))
|
|
def test_page_with_only_text_gets_text_removed(
|
|
self, page_with_text, error_tolerance
|
|
):
|
|
result_page = remove_primary_text_regions(page_with_text)
|
|
relative_error = (
|
|
np.sum(result_page != apply_threshold_to_image(page_with_text))
|
|
/ result_page.size
|
|
)
|
|
assert relative_error <= error_tolerance
|
|
|
|
@pytest.mark.parametrize("image_size", [(200, 200), (500, 500), (800, 800)])
|
|
@pytest.mark.parametrize("n_images", [1, 2])
|
|
@pytest.mark.parametrize("font_scale", [1, 1.5, 2])
|
|
@pytest.mark.parametrize(
|
|
"font_style", [cv2.FONT_HERSHEY_SIMPLEX, cv2.FONT_HERSHEY_COMPLEX]
|
|
)
|
|
@pytest.mark.parametrize("text_types", powerset(["body", "header", "caption"]))
|
|
def test_page_with_images_and_text_keeps_images(
|
|
self, page_with_images_and_text, error_tolerance
|
|
):
|
|
result_page = remove_primary_text_regions(page_with_images_and_text)
|
|
relative_error = (
|
|
np.sum(result_page != apply_threshold_to_image(page_with_images_and_text))
|
|
/ result_page.size
|
|
)
|
|
assert relative_error <= error_tolerance
|