Fix/fix ocr region to elements bug #3891
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a bug in
build_layout_elements_from_ocr_regions
where texts are joint in incorrect orders.The bug is due to incorrect masking of the
ocr_regions
after some are already selected as one of the final groups. The fix uses simpler method to mask the indices by simply use the same indices that adds the regions to the final groups to mask them so they are not considered again.Testing
This PR adds a unit test specifically aimed for this bug. Without the fix the test would fail.
Additionally any PDF files with repeated texts has a potential to trigger this bug. e.g., create a simple pdf use the test text
"LayoutParser: \n\nA Unified Toolkit for Deep Learning Based Document Image\n\nLayoutParser for Deep Learning"
and partition with
ocr_only
mode on main branch would hit this bug and output text where position of the second "LayoutParser" is incorrect.