Skip to content

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

refactor(data/utils.py): remove unnecessary decorator and improve image loading

myhloli4f7ef05d1253
diff --git a/magic_pdf/data/utils.py b/magic_pdf/data/utils.py
index 0cb22848..137bf6d2 100644
--- a/magic_pdf/data/utils.py
+++ b/magic_pdf/data/utils.py
@@ -29,7 +29,6 @@ def fitz_doc_to_image(doc, dpi=200) -> dict:
return img_dict
-@ImportPIL
def load_images_from_pdf(pdf_bytes: bytes, dpi=200, start_page_id=0, end_page_id=None) -> list:
images = []
with fitz.open('pdf', pdf_bytes) as doc:
diff --git a/magic_pdf/model/sub_modules/language_detection/yolov11/YOLOv11.py b/magic_pdf/model/sub_modules/language_detection/yolov11/YOLOv11.py
index f93d77c8..11764d3f 100644
--- a/magic_pdf/model/sub_modules/language_detection/yolov11/YOLOv11.py
+++ b/magic_pdf/model/sub_modules/language_detection/yolov11/YOLOv11.py
@@ -2,7 +2,7 @@
import time
from collections import Counter
from uuid import uuid4
-
+import cv2
import numpy as np
import torch
from loguru import logger
@@ -29,7 +29,7 @@ def split_images(image, result_images=None):
if result_images is None:
result_images = []
- width, height = image.shape[:2]
+ height, width = image.shape[:2]
long_side = max(width, height) # 获取较长边长度
if long_side <= 400:
@@ -68,14 +68,8 @@ def resize_images_to_224(image):
Works directly with NumPy arrays.
"""
try:
- # Handle numpy array directly
- if len(image.shape) == 3: # Color image
- height, width, channels = image.shape
- else: # Grayscale image
- height, width = image.shape
- image = np.stack([image] * 3, axis=2) # Convert to RGB
-
- import cv2
+ height, width = image.shape[:2]
+
if width < 224 or height < 224:
# Create black background
new_image = np.zeros((224, 224, 3), dtype=np.uint8)