Skip to content

Commit

Permalink
Merge pull request #612 from PonteIneptique/fix-empty-bbox-serialization
Browse files Browse the repository at this point in the history
Fixes serialization of dummy boxes
  • Loading branch information
mittagessen authored Jun 18, 2024
2 parents 0309bc1 + cbf1cd1 commit 4d73479
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions kraken/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ def serialize(results: 'Segmentation',
reg = reg_dict[record.regions[0]]
regs_with_lines.add(reg.id)
region = {'id': reg.id,
'bbox': max_bbox([reg.boundary]),
'boundary': [list(x) for x in reg.boundary],
'bbox': max_bbox([reg.boundary]) if reg.boundary else [],
'boundary': [list(x) for x in reg.boundary] if reg.boundary else [],
'tags': reg.tags,
'lines': [],
'type': 'region'
Expand Down
2 changes: 1 addition & 1 deletion kraken/templates/alto
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
{% if loop.previtem and loop.previtem.type == 'line' %}
</TextBlock>
{% endif %}
<TextBlock ID="{{ entity.id }}" HPOS="{{ entity.bbox[0] }}" VPOS="{{ entity.bbox[1] }}" WIDTH="{{ entity.bbox[2] - entity.bbox[0] }}" HEIGHT="{{ entity.bbox[3] - entity.bbox[1] }}" {% if entity.tags %}{% for type in page.region_types %}{% if type in entity.tags.values() %}TAGREFS="REGION_TYPE_{{ loop.index }}"{% endif %}{% endfor %}{% endif %}>
<TextBlock ID="{{ entity.id }}" {% if entity.bbox %}HPOS="{{ entity.bbox[0] }}" VPOS="{{ entity.bbox[1] }}" WIDTH="{{ entity.bbox[2] - entity.bbox[0] }}" HEIGHT="{{ entity.bbox[3] - entity.bbox[1] }}"{% endif %} {% if entity.tags %}{% for type in page.region_types %}{% if type in entity.tags.values() %}TAGREFS="REGION_TYPE_{{ loop.index }}"{% endif %}{% endfor %}{% endif %}>
<Shape>
<Polygon POINTS="{{ entity.boundary|sum(start=[])|join(' ') }}"/>
</Shape>
Expand Down
2 changes: 1 addition & 1 deletion kraken/templates/pagexml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</TextRegion>
{% endif %}
<TextRegion id="{{ entity.id }}" custom="structure {type:{{ entity.region_type }};}">
<Coords points="{% for point in entity.boundary %}{{ point|join(',') }}{% if not loop.last %} {% endif %}{% endfor %}"/>
{% if entity.boundary %}<Coords points="{% for point in entity.boundary %}{{ point|join(',') }}{% if not loop.last %} {% endif %}{% endfor %}"/>{% endif %}
{%- for line in entity.lines -%}
{{ render_line(line) }}
{%- endfor %}
Expand Down

0 comments on commit 4d73479

Please sign in to comment.