Skip to content
Open
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions deepdoc/parser/mineru_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ def _line_tag(self, bx):
return "@@{}\t{:.1f}\t{:.1f}\t{:.1f}\t{:.1f}##".format("-".join([str(p) for p in pn]), x0, x1, top, bott)

def crop(self, text, ZM=1, need_position=False):
imgs = []
poss = self.extract_positions(text)
if not poss:
if need_position:
Expand Down Expand Up @@ -416,7 +415,12 @@ def crop(self, text, ZM=1, need_position=False):
)

positions = []
imgs = []
head_ctx_end = 0
tail_ctx_start = 0
for ii, (pns, left, right, top, bottom) in enumerate(poss):
if ii + 1 == len(poss):
tail_ctx_start = len(imgs)
right = left + max_width

if bottom <= top:
Expand Down Expand Up @@ -468,6 +472,9 @@ def crop(self, text, ZM=1, need_position=False):
positions.append((pn + self.page_from, x0, x1, y0, y1))
bottom -= page.size[1]

if ii == 0:
head_ctx_end = len(imgs)

if not imgs:
if need_position:
return None, None
Expand All @@ -481,7 +488,7 @@ def crop(self, text, ZM=1, need_position=False):
pic = Image.new("RGB", (width, height), (245, 245, 245))
height = 0
for ii, img in enumerate(imgs):
if ii == 0 or ii + 1 == len(imgs):
if ii < head_ctx_end or ii >= tail_ctx_start:
img = img.convert("RGBA")
overlay = Image.new("RGBA", img.size, (0, 0, 0, 0))
overlay.putalpha(128)
Expand Down
Loading