Merge in RR/cv-analysis from remove_pil to master
Squashed commit of the following:
commit 83c8d88f3d48404251470176c70979ee75ae068b
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jul 21 10:51:51 2022 +0200
remove deprecated server tests
commit cebc03b5399ac257a74036b41997201f882f5b74
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Thu Jul 21 10:51:08 2022 +0200
remove deprecated server tests
commit ce2845b0c51f001b7b5b8b195d6bf7e034ec4e39
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Jul 20 17:05:00 2022 +0200
repair tests to work without pillow WIP
commit 023fdab8322f28359a24c63e32635a3d0deccbe4
Author: Isaac Riley <Isaac.Riley@iqser.com>
Date: Wed Jul 20 16:40:36 2022 +0200
fixed typo
commit 33850ca83a175f74789ae6b9bebd057ed84b7fb3
Author: Isaac Riley <Isaac.Riley@iqser.com>
Date: Wed Jul 20 16:38:37 2022 +0200
fixed import from refactored open_img.py
commit dbc6d345f074e538948e2c4f94ebed8a5ef520bc
Author: Isaac Riley <Isaac.Riley@iqser.com>
Date: Wed Jul 20 16:32:42 2022 +0200
removed PIL from production code, now inly in scripts
44 lines
2.2 KiB
Python
44 lines
2.2 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_image
|
|
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
|