Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
MinerU
Commits
1e01ffcf
Commit
1e01ffcf
authored
May 24, 2025
by
myhloli
Browse files
fix(ocr): adjust area ratio threshold and update fitz document handling in image conversion
parent
4949dd0c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
5 deletions
+5
-5
magic_pdf/data/utils.py
magic_pdf/data/utils.py
+4
-4
magic_pdf/model/batch_analyze.py
magic_pdf/model/batch_analyze.py
+1
-1
No files found.
magic_pdf/data/utils.py
View file @
1e01ffcf
...
@@ -10,22 +10,22 @@ from loguru import logger
...
@@ -10,22 +10,22 @@ from loguru import logger
def
fitz_doc_to_image
(
doc
,
dpi
=
200
)
->
dict
:
def
fitz_doc_to_image
(
page
,
dpi
=
200
)
->
dict
:
"""Convert fitz.Document to image, Then convert the image to numpy array.
"""Convert fitz.Document to image, Then convert the image to numpy array.
Args:
Args:
doc
(_type_): pymudoc page
page
(_type_): pymudoc page
dpi (int, optional): reset the dpi of dpi. Defaults to 200.
dpi (int, optional): reset the dpi of dpi. Defaults to 200.
Returns:
Returns:
dict: {'img': numpy array, 'width': width, 'height': height }
dict: {'img': numpy array, 'width': width, 'height': height }
"""
"""
mat
=
fitz
.
Matrix
(
dpi
/
72
,
dpi
/
72
)
mat
=
fitz
.
Matrix
(
dpi
/
72
,
dpi
/
72
)
pm
=
doc
.
get_pixmap
(
matrix
=
mat
,
alpha
=
False
)
pm
=
page
.
get_pixmap
(
matrix
=
mat
,
alpha
=
False
)
# If the width or height exceeds 4500 after scaling, do not scale further.
# If the width or height exceeds 4500 after scaling, do not scale further.
if
pm
.
width
>
4500
or
pm
.
height
>
4500
:
if
pm
.
width
>
4500
or
pm
.
height
>
4500
:
pm
=
doc
.
get_pixmap
(
matrix
=
fitz
.
Matrix
(
1
,
1
),
alpha
=
False
)
pm
=
page
.
get_pixmap
(
matrix
=
fitz
.
Matrix
(
1
,
1
),
alpha
=
False
)
# Convert pixmap samples directly to numpy array
# Convert pixmap samples directly to numpy array
img
=
np
.
frombuffer
(
pm
.
samples
,
dtype
=
np
.
uint8
).
reshape
(
pm
.
height
,
pm
.
width
,
3
)
img
=
np
.
frombuffer
(
pm
.
samples
,
dtype
=
np
.
uint8
).
reshape
(
pm
.
height
,
pm
.
width
,
3
)
...
...
magic_pdf/model/batch_analyze.py
View file @
1e01ffcf
...
@@ -156,7 +156,7 @@ class BatchAnalyze:
...
@@ -156,7 +156,7 @@ class BatchAnalyze:
res_area
=
get_coords_and_area
(
res
)[
4
]
res_area
=
get_coords_and_area
(
res
)[
4
]
if
res_area
>
0
:
if
res_area
>
0
:
ratio
=
ocr_res_area
/
res_area
ratio
=
ocr_res_area
/
res_area
if
ratio
>
0.
4
5
:
if
ratio
>
0.
2
5
:
res
[
"category_id"
]
=
1
res
[
"category_id"
]
=
1
else
:
else
:
continue
continue
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment