From 3982aee5fdee812022f062bef47cd0261fb411c3 Mon Sep 17 00:00:00 2001 From: Benjamin Kiessling Date: Mon, 22 Apr 2024 15:26:46 +0200 Subject: [PATCH] Improved dict-style region detection in Segmentation Current test would crash if the first type in region dictionary would not contain any regions. Fixes #592 --- kraken/containers.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/kraken/containers.py b/kraken/containers.py index 81aad2930..1a5be2230 100644 --- a/kraken/containers.py +++ b/kraken/containers.py @@ -194,11 +194,14 @@ def __post_init__(self): if len(self.lines) and not isinstance(self.lines[0], BBoxLine) and not isinstance(self.lines[0], BaselineLine): line_cls = BBoxLine if self.type == 'bbox' else BaselineLine self.lines = [line_cls(**line) for line in self.lines] - if len(self.regions) and not isinstance(next(iter(self.regions.values()))[0], Region): - regs = {} - for k, v in self.regions.items(): - regs[k] = [Region(**reg) for reg in v] - self.regions = regs + if len(self.regions): + for regs in self.regions.values(): + if regs and not isinstance(regs[0], Region): + regs = {} + for k, v in self.regions.items(): + regs[k] = [Region(**reg) for reg in v] + self.regions = regs + break class ocr_record(ABC):