Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Left and Right blocks aren't sorted #113

Closed
AnzorGozalishvili opened this issue Jan 10, 2022 · 1 comment
Closed

Left and Right blocks aren't sorted #113

AnzorGozalishvili opened this issue Jan 10, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@AnzorGozalishvili
Copy link

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
  3. I installed layoutparser using pip and the installed detectron2 from source.

Error traceback
N/A

Screenshots
image

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

@AnzorGozalishvili AnzorGozalishvili added the bug Something isn't working label Jan 10, 2022
@lolipopshock
Copy link
Member

lolipopshock commented Jan 12, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants