From 401dfa4e4f7472ca5631d98eb531e911073681c7 Mon Sep 17 00:00:00 2001 From: myhloli Date: Tue, 5 Nov 2024 16:10:19 +0800 Subject: [PATCH] fix(table): improve table image processing - Replace np.array with np.asarray for better performance - Add image color conversion from RGB to BGR using OpenCV --- magic_pdf/model/ppTableModel.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/magic_pdf/model/ppTableModel.py b/magic_pdf/model/ppTableModel.py index 19669237..3f08d78d 100644 --- a/magic_pdf/model/ppTableModel.py +++ b/magic_pdf/model/ppTableModel.py @@ -1,3 +1,4 @@ +import cv2 from paddleocr.ppstructure.table.predict_table import TableSystem from paddleocr.ppstructure.utility import init_args from magic_pdf.libs.Constants import * @@ -36,7 +37,8 @@ class ppTableModel(object): - HTML (str): A string representing the HTML structure with content of the table. """ if isinstance(image, Image.Image): - image = np.array(image) + image = np.asarray(image) + image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) pred_res, _ = self.table_sys(image) pred_html = pred_res["html"] # res = '' + pred_html.replace("
", "").replace(