Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
fix(ocr): adjust area ratio threshold and update fitz document handling in image conversion
myhloli1e01ffcf784b
diff --git a/magic_pdf/data/utils.py b/magic_pdf/data/utils.pyindex 9ddf3a30..849fa780 100644--- a/magic_pdf/data/utils.py+++ b/magic_pdf/data/utils.py@@ -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.Args:- doc (_type_): pymudoc page+ page (_type_): pymudoc pagedpi (int, optional): reset the dpi of dpi. Defaults to 200.Returns:dict: {'img': numpy array, 'width': width, 'height': height }"""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 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 arrayimg = np.frombuffer(pm.samples, dtype=np.uint8).reshape(pm.height, pm.width, 3)diff --git a/magic_pdf/model/batch_analyze.py b/magic_pdf/model/batch_analyze.pyindex 5d140013..be5e331f 100644--- a/magic_pdf/model/batch_analyze.py+++ b/magic_pdf/model/batch_analyze.py@@ -156,7 +156,7 @@ class BatchAnalyze:res_area = get_coords_and_area(res)[4]if res_area > 0:ratio = ocr_res_area / res_area- if ratio > 0.45:+ if ratio > 0.25:res["category_id"] = 1else:continue