Update demo_page_hf.py

This commit is contained in:
Hao Feng 2025-06-23 20:20:57 +08:00 committed by GitHub
parent 675dceb08e
commit 98b8ccc38d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -201,7 +201,7 @@ def process_elements(layout_results, padded_image, dims, model, max_batch_size,
# Crop and parse element
cropped = padded_image[y1:y2, x1:x2]
if cropped.size > 0:
if cropped.size > 0 and cropped.shape[0] > 3 and cropped.shape[1] > 3:
if label == "fig":
pil_crop = Image.fromarray(cv2.cvtColor(cropped, cv2.COLOR_BGR2RGB))
@ -212,8 +212,8 @@ def process_elements(layout_results, padded_image, dims, model, max_batch_size,
figure_results.append(
{
"label": label,
"text": f"![Figure](figures/{figure_filename})", # 相对路径
"figure_path": f"figures/{figure_filename}", # 添加专门的路径字段
"text": f"![Figure](figures/{figure_filename})",
"figure_path": f"figures/{figure_filename}",
"bbox": [orig_x1, orig_y1, orig_x2, orig_y2],
"reading_order": reading_order,
}