(self, page, png_image)
| 128 | png_image.save(debug_file) |
| 129 | |
| 130 | def render_layout_boxes(self, page, png_image): |
| 131 | layout_bboxes = [] |
| 132 | layout_labels = [] |
| 133 | for block_id in page.structure: |
| 134 | child = page.get_block(block_id) |
| 135 | if child.block_type in [BlockTypes.Line, BlockTypes.Span]: |
| 136 | continue |
| 137 | |
| 138 | bbox = child.polygon.rescale(page.polygon.size, png_image.size).bbox |
| 139 | layout_bboxes.append(bbox) |
| 140 | layout_labels.append(str(child.block_type)) |
| 141 | |
| 142 | self.render_on_image( |
| 143 | layout_bboxes, |
| 144 | png_image, |
| 145 | labels=layout_labels, |
| 146 | color="red", |
| 147 | label_font_size=24, |
| 148 | ) |
| 149 | |
| 150 | order_labels = [str(i) for i in range(len(layout_bboxes))] |
| 151 | self.render_on_image( |
| 152 | layout_bboxes, |
| 153 | png_image, |
| 154 | labels=order_labels, |
| 155 | color="green", |
| 156 | draw_bbox=False, |
| 157 | label_offset=5, |
| 158 | label_font_size=24, |
| 159 | ) |
| 160 | return png_image |
| 161 | |
| 162 | def dump_block_debug_data(self, document: Document): |
| 163 | debug_file = os.path.join(self.debug_folder, "blocks.json") |
no test coverage detected