docling-project / docling-project/docling
Diffferent Bounding Box Origins within DocTags Format when add_table_cell_location=True
- Dominant language
- Python
- Stars
- 66.4k
- Forks
- 4.8k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 84
Description
### Question
Is the origin for bounding box locations meant to be different between table cell locations (bottom left origin) and other document tokens (top left origin)?
I've been working with the DocTag format for custom post-processing of PDF files, using bounding boxes for annotations on the original document, and noticed the bounding boxes were misplaced for different tokens. After looking into `docling_core`, I saw the cell location origin is set to the bottom left for table cells and the top left for other document tokens.
#### Chunk from TableItem.export_to_otsl -
```
cell_loc = DocumentToken.get_location(
bbox=cell.bbox.to_bottom_left_origin(page_h).as_tuple(),
page_w=page_w,
page_h=page_h,
xsize=xsize,
ysize=ysize
)
```
#### Chunk from DocItem.get_location_tokens -
```
loc_str = DocumentToken.get_location(
bbox=prov.bbox.to_top_left_origin(page_h).as_tuple(),
page_w=page_w,
page_h=page_h,
xsize=xsize,
ysize=ysize
)
```
If this distinction is intentional, is it possible to set a unified origin for all tokens when exporting to the DocTags format?
#### Reproducing
Unfortunately I can't share my PDF document, but here's a small adjustment to the Custom Conversion example in the docs.
```
data_folder = Path(__file__).parent / "../../tests/data"
input_doc_path = data_folder / "pdf/2206.01062.pdf"
pipeline_options = PdfPipelineOptions()
pipeline_options.do_ocr = True
pipeline_options.do_table_structure = True
pipeline_options.table_structure_options.do_cell_matching = True
pipeline_options.ocr_options.lang = ["es"]
pipeline_options.accelerator_options = AcceleratorOptions(
num_threads=4, device=AcceleratorDevice.AUTO
)
doc_converter = DocumentConverter(
format_options={
InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)
}
)
conv_result = doc_converter.convert(input_doc_path)
output_dir = Path("scratch")
output_dir.mkdir(parents=True, exist_ok=True)
doc_filename = conv_result.input.file.stem
with (output_dir / f'{doc_filename}.doctags').open('w', encoding='utf-8') as fp:
fp.write(conv_result.document.export_to_doctags(add_table_cell_location=True, xsize=612, ysize=792))
```
Contributor guide
Assessment
This issue has not been assessed yet.