Merge in RR/cv-analysis from pdf2image to master
Squashed commit of the following:
commit 1353f54d2dceb0a79b1f81bfa2c035f5a454275a
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Wed Aug 10 09:07:31 2022 +0200
add deRotation and transformation vie rectanglePlus
commit 51459dbf57a86e3eac66ec0da02de40dc1b68796
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Tue Aug 9 08:53:50 2022 +0200
add derotation and to pdf coords transformation to cv-analysis output
commit 733991e2f5a4664205b2f7cc756cebcbc9ee3930
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date: Mon Aug 8 15:15:13 2022 +0200
update pipline with detrotation logic WIP
76 lines
2.3 KiB
Python
76 lines
2.3 KiB
Python
import fitz
|
|
import numpy as np
|
|
import pytest
|
|
|
|
from cv_analysis.server.pipeline import make_analysis_pipeline
|
|
from cv_analysis.utils.structures import Rectangle
|
|
|
|
|
|
def analysis_fn_mock(image: np.ndarray):
|
|
bbox = (0, 0, 42, 42)
|
|
return [Rectangle.from_xyxy(bbox)]
|
|
|
|
|
|
@pytest.fixture
|
|
def empty_pdf(n_pages):
|
|
doc = fitz.open()
|
|
for n in range(n_pages):
|
|
doc.new_page()
|
|
return doc.write()
|
|
|
|
|
|
@pytest.fixture
|
|
def expected_formatted_analysis_result(n_pages, reduced):
|
|
if reduced:
|
|
return [
|
|
{
|
|
"pageInfo": {
|
|
"number": page_number,
|
|
"rotation": 0,
|
|
"width": 595.0,
|
|
"height": 842.0,
|
|
},
|
|
"boundingBox": {
|
|
"x0": 0.0,
|
|
"y0": 826.8800048828125,
|
|
"x1": 15.119999885559082,
|
|
"y1": 842.0,
|
|
"width": 15.119999885559082,
|
|
"height": 15.1199951171875,
|
|
},
|
|
"alpha": False,
|
|
}
|
|
for page_number in range(n_pages)
|
|
]
|
|
return [
|
|
{
|
|
"pageInfo": {
|
|
"number": page_number,
|
|
"rotation": 0,
|
|
"width": 595.0,
|
|
"height": 842.0,
|
|
"deRotationMatrix": (1.0, -0.0, -0.0, 1.0, 0.0, 0.0),
|
|
"transformationMatrix": (1.0, 0.0, 0.0, -1.0, -0.0, 842.0),
|
|
},
|
|
"boundingBox": {
|
|
"x0": 0.0,
|
|
"y0": 826.8800048828125,
|
|
"x1": 15.119999885559082,
|
|
"y1": 842.0,
|
|
"width": 15.119999885559082,
|
|
"height": 15.1199951171875,
|
|
},
|
|
"boundingBoxScreen": {"x0": 0.0, "y0": 0.0, "x1": 15.12, "y1": 15.12, "width": 15.12, "height": 15.12},
|
|
"alpha": False,
|
|
}
|
|
for page_number in range(n_pages)
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("n_pages", [1, 2])
|
|
@pytest.mark.parametrize("reduced", [True, False])
|
|
def test_analysis_pipeline(empty_pdf, expected_formatted_analysis_result, reduced):
|
|
analysis_pipeline = make_analysis_pipeline(analysis_fn_mock, reduced=reduced)
|
|
results = analysis_pipeline(empty_pdf)
|
|
assert list(results) == expected_formatted_analysis_result
|