Skip to content

Commit

Permalink
fix layout recovery import error
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatV committed Jul 19, 2024
1 parent 603b372 commit e0f35a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 12 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 4 additions & 5 deletions paddleocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand All @@ -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"]
Expand Down Expand Up @@ -991,18 +995,13 @@ 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)
all_res += result_sorted

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(
Expand Down

0 comments on commit e0f35a3

Please sign in to comment.