| Conditions | 3 |
| Total Lines | 17 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | from ocrd_utils import xywh_from_points |
||
| 9 | @_export |
||
| 10 | def pc_pixelarea(nodes): |
||
| 11 | """ |
||
| 12 | Extract Coords/@points from all nodes, calculate the bounding |
||
| 13 | box, and accumulate areas. |
||
| 14 | """ |
||
| 15 | area = 0 |
||
| 16 | for node in nodes: |
||
| 17 | # FIXME: find out why we need to go to the parent here |
||
| 18 | node = node.parent.value |
||
| 19 | coords = node.find(f'{node.prefix}:Coords', node.nsmap) |
||
| 20 | if coords is None: |
||
| 21 | continue |
||
| 22 | points = coords.attrib['points'] |
||
| 23 | xywh = xywh_from_points(points) |
||
| 24 | area += xywh['w'] * xywh['h'] |
||
| 25 | return area |
||
| 26 | |||
| 52 |