Refactoring: Move

This commit is contained in:
Matthias Bisping 2023-02-01 16:42:55 +01:00
parent 845d169194
commit bdcb2f1bef
2 changed files with 12 additions and 11 deletions

View File

@ -2,6 +2,8 @@ from functools import partial
from itertools import starmap, compress
from typing import Iterable, List, Sequence
from funcy import lremove
from cv_analysis.utils.rectangle import Rectangle
@ -21,6 +23,16 @@ def remove_included(rectangles: Iterable[Rectangle]) -> List[Rectangle]:
return rectangles_to_keep
def remove_small(boxes: Iterable[Rectangle], page_width, page_height, min_percentage=0.13) -> List[Rectangle]:
min_width = page_width * min_percentage
min_height = page_height * min_percentage
def small(box: Rectangle):
return box.width < min_width or box.height < min_height
return lremove(small, boxes)
def __remove_isolated_unsorted(rectangles: Iterable[Rectangle]) -> List[Rectangle]:
def is_connected(rect: Rectangle, rectangles: Iterable[Rectangle]):
return any(rect.adjacent(rect2) for rect2 in rectangles if not rect == rect2)

View File

@ -60,7 +60,6 @@ from funcy import (
omit,
project,
complement,
lremove,
chunks,
)
@ -1297,16 +1296,6 @@ def get_child_boxes(box: Rectangle, split_coordinate, axis, margin_percentage) -
)
def drop_small_boxes(boxes: Iterable[Rectangle], page_width, page_height, min_percentage=0.13) -> List[Rectangle]:
min_width = page_width * min_percentage
min_height = page_height * min_percentage
def small(box: Rectangle):
return box.width < min_width or box.height < min_height
return lremove(small, boxes)
@pytest.fixture(
params=[
TwoColumnPagePartitioner,