Layout-Parser / layout-parser

A Unified Toolkit for Deep Learning Based Document Image Analysis
https://layout-parser.github.io/
Apache License 2.0
4.67k stars 449 forks source link

Left and Right blocks aren't sorted #113

Closed AnzorGozalishvili closed 2 years ago

AnzorGozalishvili commented 2 years ago

Describe the bug Bug in the python code while sorting layout blocks.

Checklist

  1. I used python "sorted" function to solve that issue.

To Reproduce Steps to reproduce the behavior:

  1. What command or script did you run?
    
    h, w = image.shape[:2]

left_interval = lp.Interval(0, w/2*1.05, axis='x').put_on_canvas(image)

left_blocks = text_blocks.filter_by(left_interval, center=True) left_blocks.sort(key = lambda b:b.coordinates[1])

right_blocks = [b for b in text_blocks if b not in left_blocks] right_blocks.sort(key = lambda b:b.coordinates[1])

And finally combine the two list and add the index

according to the order

text_blocks = lp.Layout([b.set(id = idx) for idx, b in enumerate(left_blocks + right_blocks)])

THIS CODE IS PASTED FROM DOCUMENTATION PAGE: https://layout-parser.readthedocs.io/en/latest/example/deep_layout_parsing/index.html



**Environment**
1. Just run on google colab
2. layoutparser version: 0.3.2
2. I installed layoutparser using pip and the installed detectron2 from source.

**Error traceback**
N/A

**Screenshots**
![image](https://user-images.githubusercontent.com/55232459/148811312-deec5c89-72a0-497a-a95b-cbc5f35a8d2a.png)

**Additional context**
Because I am short in time I've created an issue for that instead of PR.
"sorted(left_blocks, key=lambda x:x.coordinates[1]))" use such sorting to fix bug.
![image](https://user-images.githubusercontent.com/55232459/148811664-aa533e5c-403a-4b1c-a10f-59cb3e8a5389.png)
lolipopshock commented 2 years ago

Thanks for mentioning this -- you might want to add inplace=True for the sort function, which should be resolved by #104 .