Constrain possible random layouts
This commit is contained in:
parent
38c0614396
commit
4ecfe16df5
20
test/fixtures/page_generation/page.py
vendored
20
test/fixtures/page_generation/page.py
vendored
@ -18,6 +18,7 @@ from matplotlib import pyplot as plt
|
||||
from cv_analysis.utils import star, rconj
|
||||
from cv_analysis.utils.filters import is_boxy
|
||||
from cv_analysis.utils.merging import merge_related_rectangles
|
||||
from cv_analysis.utils.postprocessing import remove_overlapping, remove_included
|
||||
|
||||
Image_t = Union[Image.Image, np.ndarray]
|
||||
#
|
||||
@ -93,6 +94,7 @@ from funcy import (
|
||||
keep,
|
||||
partition,
|
||||
split,
|
||||
lsplit,
|
||||
)
|
||||
|
||||
from cv_analysis.locations import TEST_PAGE_TEXTURES_DIR
|
||||
@ -145,9 +147,9 @@ Color = Tuple[int, int, int]
|
||||
@pytest.fixture(
|
||||
params=[
|
||||
# "rough_grain",
|
||||
# "plain",
|
||||
"plain",
|
||||
# "digital",
|
||||
"crumpled",
|
||||
# "crumpled",
|
||||
]
|
||||
)
|
||||
def base_texture(request, size):
|
||||
@ -368,12 +370,20 @@ class ContentGenerator:
|
||||
def __call__(self, boxes: List[Rectangle]) -> Image:
|
||||
random.shuffle(boxes)
|
||||
|
||||
plot_boxes, text_boxes = split(is_square_like, boxes)
|
||||
plot_boxes, text_boxes = lsplit(is_square_like, boxes)
|
||||
|
||||
plot_boxes = merge_related_rectangles(plot_boxes)
|
||||
plot_boxes = filter(is_square_like, plot_boxes)
|
||||
text_boxes = merge_related_rectangles(text_boxes)
|
||||
|
||||
text_boxes = lmap(generate_random_text_block, text_boxes)
|
||||
plots = lmap(generate_random_plot, plot_boxes)
|
||||
|
||||
return text_boxes + plots
|
||||
boxes = text_boxes + plots
|
||||
boxes = remove_included(boxes)
|
||||
boxes = remove_overlapping(boxes)
|
||||
|
||||
return boxes
|
||||
|
||||
|
||||
def is_square_like(box: Rectangle):
|
||||
@ -540,7 +550,7 @@ class RandomTextBlock(ContentRectangle):
|
||||
|
||||
image = Image.new("RGBA", (rectangle.width, rectangle.height), (0, 255, 255, 0))
|
||||
draw = ImageDraw.Draw(image)
|
||||
text = Faker().paragraph(nb_sentences=1000, variable_nb_sentences=False, ext_word_list=None)
|
||||
text = Faker().paragraph(nb_sentences=3000, variable_nb_sentences=False, ext_word_list=None)
|
||||
|
||||
wrapped_text = textwrap.wrap(text, width=image.width, break_long_words=False)
|
||||
text_size = draw.textsize(first(wrapped_text), font=self.font)[1]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user