cv-analysis-service/tests/test_redaction_detection.py

34 lines
863 B
Python

from vidocp.redaction_detection import find_redactions
import numpy as np
import pytest
import pdf2image
@pytest.fixture()
def image():
page_index = 0
pdf_path = "/home/lillian/vidocp/tests/CropBoxNotEqualToMediabox_redacted.pdf"
page = pdf2image.convert_from_path(pdf_path, first_page=page_index + 1, last_page=page_index + 1)[0]
page = np.array(page)
return page
@pytest.fixture()
def contours(image):
redaction_contours = find_redactions(image)
return redaction_contours
def test_number_of_redaction(contours):
assert len(list(contours)) == 1
def test_is_black(image, contours):
for contour in contours:
cont = contour.tolist()
x1, y1 = min(cont)[0]
x2, y2 = max(cont)[0]
redaction = image[y1:y2, x1:x2]
for pixel in redaction:
assert pixel.all() < 10