23 lines
764 B
Python
23 lines
764 B
Python
from cv_analysis.utils.rectangle import Rectangle
|
|
from synthesis.partitioner.page_partitioner import PagePartitioner
|
|
from synthesis.random import rnd
|
|
|
|
|
|
class RandomPagePartitioner(PagePartitioner):
|
|
def __init__(self):
|
|
super().__init__()
|
|
|
|
def generate_content_boxes(self, box: Rectangle, depth=0):
|
|
if depth >= self.max_recursion_depth:
|
|
yield box
|
|
else:
|
|
child_boxes = self.generate_child_boxes(
|
|
box,
|
|
axis=rnd.choice(["x", "y"]),
|
|
split_percentage=rnd.uniform(0.3, 0.7),
|
|
)
|
|
if self.recurse(depth):
|
|
yield from (self.generate_content_boxes(b, depth + 1) for b in child_boxes)
|
|
else:
|
|
yield child_boxes
|