Vik Paruchuri
commited on
Commit
·
74b25e3
1
Parent(s):
48ceeb2
Return RGB images
Browse files- marker/schema/groups/page.py +10 -4
marker/schema/groups/page.py
CHANGED
|
@@ -56,6 +56,10 @@ class PageGroup(Group):
|
|
| 56 |
):
|
| 57 |
image = self.highres_image if highres else self.lowres_image
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
# Avoid double OCR for certain elements
|
| 60 |
if remove_blocks:
|
| 61 |
image = image.copy()
|
|
@@ -245,13 +249,15 @@ class PageGroup(Group):
|
|
| 245 |
):
|
| 246 |
# Add lines to the proper blocks, sorted in order
|
| 247 |
for block_id, lines in block_lines.items():
|
| 248 |
-
line_extraction_methods = set(
|
|
|
|
|
|
|
| 249 |
if len(line_extraction_methods) == 1:
|
| 250 |
lines = sorted(lines, key=lambda x: x[0])
|
| 251 |
-
lines = [
|
| 252 |
else:
|
| 253 |
-
lines = [
|
| 254 |
-
line_polygons = [
|
| 255 |
sorted_line_polygons = sort_text_lines(line_polygons)
|
| 256 |
argsort = [line_polygons.index(p) for p in sorted_line_polygons]
|
| 257 |
lines = [lines[i] for i in argsort]
|
|
|
|
| 56 |
):
|
| 57 |
image = self.highres_image if highres else self.lowres_image
|
| 58 |
|
| 59 |
+
# Check if RGB, convert if needed
|
| 60 |
+
if isinstance(image, Image.Image) and image.mode != "RGB":
|
| 61 |
+
image = image.convert("RGB")
|
| 62 |
+
|
| 63 |
# Avoid double OCR for certain elements
|
| 64 |
if remove_blocks:
|
| 65 |
image = image.copy()
|
|
|
|
| 249 |
):
|
| 250 |
# Add lines to the proper blocks, sorted in order
|
| 251 |
for block_id, lines in block_lines.items():
|
| 252 |
+
line_extraction_methods = set(
|
| 253 |
+
[line[1].line.text_extraction_method for line in lines]
|
| 254 |
+
)
|
| 255 |
if len(line_extraction_methods) == 1:
|
| 256 |
lines = sorted(lines, key=lambda x: x[0])
|
| 257 |
+
lines = [line for _, line in lines]
|
| 258 |
else:
|
| 259 |
+
lines = [line for _, line in lines]
|
| 260 |
+
line_polygons = [line.line.polygon for line in lines]
|
| 261 |
sorted_line_polygons = sort_text_lines(line_polygons)
|
| 262 |
argsort = [line_polygons.index(p) for p in sorted_line_polygons]
|
| 263 |
lines = [lines[i] for i in argsort]
|