From e0f35a377aa3c5699dc9a84405bb247b467504df Mon Sep 17 00:00:00 2001 From: Wang Xin Date: Fri, 19 Jul 2024 01:04:00 +0000 Subject: [PATCH] fix layout recovery import error --- __init__.py | 13 ++++++++++++- paddleocr.py | 9 ++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/__init__.py b/__init__.py index 7233b3c0ed..e57c0c764b 100644 --- a/__init__.py +++ b/__init__.py @@ -11,13 +11,24 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -from .paddleocr import * +from .paddleocr import ( + PaddleOCR, + PPStructure, + draw_ocr, + draw_structure_result, + save_structure_res, + download_with_progressbar, + sorted_layout_boxes, + convert_info_docx, + to_excel, +) import importlib.metadata as importlib_metadata try: __version__ = importlib_metadata.version(__package__ or __name__) except importlib_metadata.PackageNotFoundError: __version__ = "0.0.0" + __all__ = [ "PaddleOCR", "PPStructure", diff --git a/paddleocr.py b/paddleocr.py index 45c7dd41dd..fa7ab72e71 100644 --- a/paddleocr.py +++ b/paddleocr.py @@ -23,6 +23,7 @@ sys.path.append(os.path.join(__dir__, "")) import cv2 +from copy import deepcopy import logging import numpy as np from pathlib import Path @@ -64,6 +65,7 @@ def _import_file(module_name, file_path, make_importable=False): from tools.infer.utility import draw_ocr, str2bool, check_gpu from ppstructure.utility import init_args, draw_structure_result from ppstructure.predict_system import StructureSystem, save_structure_res, to_excel +from ppstructure.recovery.recovery_to_doc import sorted_layout_boxes, convert_info_docx logger = get_logger() @@ -75,6 +77,8 @@ def _import_file(module_name, file_path, make_importable=False): "save_structure_res", "download_with_progressbar", "to_excel", + "sorted_layout_boxes", + "convert_info_docx", ] SUPPORT_DET_MODEL = ["DB"] @@ -991,9 +995,6 @@ def main(): save_structure_res(result, args.output, img_name, index) if args.recovery and result != []: - from copy import deepcopy - from ppstructure.recovery.recovery_to_doc import sorted_layout_boxes - h, w, _ = img.shape result_cp = deepcopy(result) result_sorted = sorted_layout_boxes(result_cp, w) @@ -1001,8 +1002,6 @@ def main(): if args.recovery and all_res != []: try: - from ppstructure.recovery.recovery_to_doc import convert_info_docx - convert_info_docx(img, all_res, args.output, img_name) except Exception as ex: logger.error(