Skip to content

Commit

Permalink
fix pdf_parser content confusion (infiniflow#1458)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

infiniflow#1407 

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
  • Loading branch information
guoyuhao2330 authored Jul 11, 2024
1 parent 4ccb001 commit 8141106
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions deepdoc/parser/pdf_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@ def __ocr(self, pagenum, img, chars, ZM=3):
self.mean_height[-1] / 3
)

# solve char content confusion
record_error_length = 0
for c in chars[0:128]:
ii = Recognizer.find_overlapped(c, bxs)
if ii is None:
continue
record_error_length += abs((bxs[ii]["bottom"] + bxs[ii]["bottom"] - c["bottom"] - c["top"]) / 2)

record_error_length = record_error_length / 128
for char in chars:
char["top"] -= record_error_length
char["bottom"] -= record_error_length

# merge chars in the same rect
for c in Recognizer.sort_X_firstly(
chars, self.mean_width[pagenum - 1] // 4):
Expand Down

0 comments on commit 8141106

Please sign in to comment.