Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Rotated block geometries become straight boxes after `Page.from_dict` + `export()`

Chiusa
#2,180 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #2181 di @RaphaelFakhri — integrata

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

The issue points to Block.__init__ and Page.export(); first inspect their geometry handling and how Page.from_dict rebuilds lines. Reproduce the round trip with the provided snippet and compare the exported block geometry. Done means the second export preserves the four point rotated polygon; linked pull request #2181 is already open.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug description

A page with rotated boxes (e.g. the output of ocr_predictor(assume_straight_pages=False)) that is saved with export() and loaded back with Document.from_dict / Page.from_dict loses its rotated block geometries on the next export(): each block polygon is replaced by a straight ((xmin, ymin), (xmax, ymax)) box.

Block.__init__ chooses between resolve_enclosing_rbbox and resolve_enclosing_bbox with isinstance(lines[0].geometry, np.ndarray). Line geometries read back from a dict are nested lists, so the straight resolution is used. Page.export() rebuilds the blocks in reading order without a geometry, which triggers this path.

Code snippet to reproduce the bug
import json
import numpy as np
from doctr.io import Block, Line, Page, Word

# Rotated word geometry, as built by the DocumentBuilder when assume_straight_pages=False
polygon = ((0.1, 0.1), (0.4, 0.2), (0.35, 0.4), (0.05, 0.3))
word = Word("hello", 0.9, polygon, 0.9, {"value": 0, "confidence": None})
page = Page(np.zeros((10, 10, 3), dtype=np.uint8), [Block([Line([word])])], 0, (10, 10))
exported = json.loads(json.dumps(page.export()))
print(np.round(exported["blocks"][0]["geometry"], 3).tolist())
print(np.round(Page.from_dict(exported).export()["blocks"][0]["geometry"], 3).tolist())

Output:

[[0.1, 0.1], [0.415, 0.205], [0.35, 0.4], [0.035, 0.295]]
[[0.05, 0.1], [0.4, 0.4]]
Error traceback

No exception: the block geometry silently changes from a 4-point polygon to a 2-point straight box.

Environment

docTR main (aa17f53), Python 3.11, Linux.

Lingua principale
Python
Stelle
6.4k
Fork
684
Merge medio
1g 5h
PR unite (30g)
28

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di mindee/doctr

Tutte le issue di mindee/doctr

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.