Skip to content

Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.

fix: validate box coordinates and aspect ratio for improved image cropping

myhloli91826697c941
diff --git a/mineru/model/table/rec/unet_table/main.py b/mineru/model/table/rec/unet_table/main.py
index 2faa175b..cc8fd639 100644
--- a/mineru/model/table/rec/unet_table/main.py
+++ b/mineru/model/table/rec/unet_table/main.py
@@ -182,10 +182,14 @@ class WiredTableRecognition:
logger.warning(f"No OCR engine provided for box {i}: {box}")
continue
# 从img中截取对应的区域
- x1, y1, x2, y2 = box[0][0], box[0][1], box[2][0], box[2][1]
+ x1, y1, x2, y2 = int(box[0][0]), int(box[0][1]), int(box[2][0]), int(box[2][1])
if x1 >= x2 or y1 >= y2:
logger.warning(f"Invalid box coordinates: {box}")
continue
+ # 判断长宽比
+ if (x2 - x1) / (y2 - y1) > 20 or (y2 - y1) / (x2 - x1) > 20:
+ logger.warning(f"Box {i} has invalid aspect ratio: {x1, y1, x2, y2}")
+ continue
img_crop = bgr_img[int(y1):int(y2), int(x1):int(x2)]
img_crop_list.append(img_crop)
img_crop_info_list.append([i, box])