28 lines
848 B
Python
28 lines
848 B
Python
from vidocp.layout_parsing import parse_layout
|
|
import pytest
|
|
import numpy as np
|
|
import pdf2image
|
|
|
|
|
|
@pytest.fixture()
|
|
def rects():
|
|
page_index = 0
|
|
pdf_path = "/home/lillian/vidocp/tests/VV-313450.pdf"
|
|
page = pdf2image.convert_from_path(pdf_path, first_page=page_index + 1, last_page=page_index + 1)[0]
|
|
page = np.array(page)
|
|
rectangles = parse_layout(page)
|
|
return rectangles
|
|
|
|
|
|
def test_number_of_layout_boxes(rects):
|
|
assert len([[x] for x in rects]) == 53
|
|
|
|
|
|
def test_layout_rects(rects):
|
|
for rect in rects:
|
|
x, y, w, h = rect
|
|
possible_xrange = (x, x + w)
|
|
possible_yrange = (y, y + h)
|
|
assert all(x <= possible_xrange[0] and x + w >= possible_xrange[1] for (x, y, w, h) in rects)
|
|
assert all(x <= possible_yrange[0] and x + w >= possible_yrange[1] for (x, y, w, h) in rects)
|
|
|