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
Update batch_analyze.py
seedclaimer400bb763747b
diff --git a/magic_pdf/model/batch_analyze.py b/magic_pdf/model/batch_analyze.pyindex 7642e3f0..743f7116 100644--- a/magic_pdf/model/batch_analyze.py+++ b/magic_pdf/model/batch_analyze.py@@ -181,17 +181,16 @@ class BatchAnalyze:# 对每个分辨率组进行批处理for group_key, group_crops in tqdm(resolution_groups.items(), desc=f"OCR-det {lang}"):- raw_images = [crop_info[0] for crop_info in group_crops]-# 计算目标尺寸(组内最大尺寸,向上取整到32的倍数)- max_h = max(img.shape[0] for img in raw_images)- max_w = max(img.shape[1] for img in raw_images)+ max_h = max(crop_info[0].shape[0] for crop_info in group_crops)+ max_w = max(crop_info[0].shape[1] for crop_info in group_crops)target_h = ((max_h + 32 - 1) // 32) * 32target_w = ((max_w + 32 - 1) // 32) * 32# 对所有图像进行padding到统一尺寸batch_images = []- for img in raw_images:+ for crop_info in group_crops:+ img = crop_info[0]h, w = img.shape[:2]# 创建目标尺寸的白色背景padded_img = np.ones((target_h, target_w, 3), dtype=np.uint8) * 255@@ -208,9 +207,32 @@ class BatchAnalyze:for i, (crop_info, (dt_boxes, elapse)) in enumerate(zip(group_crops, batch_results)):new_image, useful_list, ocr_res_list_dict, res, adjusted_mfdetrec_res, _lang = crop_info- if dt_boxes is not None:- # 构造OCR结果格式 - 每个box应该是4个点的列表- ocr_res = [box.tolist() for box in dt_boxes]+ if dt_boxes is not None and len(dt_boxes) > 0:+ # 直接应用原始OCR流程中的关键处理步骤+ from magic_pdf.model.sub_modules.ocr.paddleocr2pytorch.ocr_utils import (+ merge_det_boxes, update_det_boxes, sorted_boxes+ )++ # 1. 排序检测框+ if len(dt_boxes) > 0:+ dt_boxes_sorted = sorted_boxes(dt_boxes)+ else:+ dt_boxes_sorted = []++ # 2. 合并相邻检测框+ if dt_boxes_sorted:+ dt_boxes_merged = merge_det_boxes(dt_boxes_sorted)+ else:+ dt_boxes_merged = []++ # 3. 根据公式位置更新检测框(关键步骤!)+ if dt_boxes_merged and adjusted_mfdetrec_res:+ dt_boxes_final = update_det_boxes(dt_boxes_merged, adjusted_mfdetrec_res)+ else:+ dt_boxes_final = dt_boxes_merged++ # 构造OCR结果格式+ ocr_res = [box.tolist() if hasattr(box, 'tolist') else box for box in dt_boxes_final]if ocr_res:ocr_result_list = get_ocr_result_list(