layout-parser icon indicating copy to clipboard operation
layout-parser copied to clipboard

Error element indices when setting `show_element_id` in the visualization

Open lolipopshock opened this issue 4 years ago • 0 comments

Describe the bug When the input sequence is ordered differently from the element ids, the lp.draw_box will create inconsistent id annotation in the visualization.

To Reproduce Example:

background = Image.new('RGB', (1000,1000), color='white')
layout = lp.Layout(
    [
        lp.TextBlock(block=lp.Rectangle(x_1=80, y_1=79.0, x_2=490, y_2=92.0), text=None, id=1, type=None, parent=0, next=None),
        lp.TextBlock(block=lp.Rectangle(x_1=80, y_1=65.0, x_2=488.0, y_2=77.0), text=None, id=0, type=None, parent=0, next=None),
        lp.TextBlock(block=lp.Rectangle(x_1=80.0, y_1=95.0, x_2=490, y_2=107.0), text=None, id=2, type=None, parent=0, next=None),
        lp.TextBlock(block=lp.Rectangle(x_1=80, y_1=110.0, x_2=490, y_2=122.0), text=None, id=3, type=None, parent=0, next=None),
        lp.TextBlock(block=lp.Rectangle(x_1=80.0, y_1=125.0, x_2=490.0, y_2=138.0), text=None, id=4, type=None, parent=0, next=None)
    ]
).scale((1,2))
lp.draw_box(background, layout, show_element_id=True)

Expected output: image

Actual output: image

Temporary fix:

lp.draw_box(background, [b.set(id=str(b.id)) for b in layout], show_element_id=True)

lolipopshock avatar May 03 '21 03:05 lolipopshock