54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
#
|
|
# Copyright 2025 The InfiniFlow Authors. All Rights Reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# 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.
|
|
#
|
|
"""
|
|
独立的 OCR 模块
|
|
|
|
此模块从 RAGFlow 项目中提取,已经移除了对 RAGFlow 特定模块的依赖。
|
|
可以直接作为独立模块使用。
|
|
|
|
使用方法:
|
|
from ocr import OCR
|
|
import cv2
|
|
|
|
ocr = OCR()
|
|
img = cv2.imread("image.jpg")
|
|
results = ocr(img)
|
|
"""
|
|
|
|
# 处理导入问题:支持直接运行和模块导入
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
try:
|
|
_package = __package__
|
|
except NameError:
|
|
_package = None
|
|
|
|
if _package is None:
|
|
# 直接运行时,添加父目录到路径并使用绝对导入
|
|
parent_dir = Path(__file__).parent.parent
|
|
if str(parent_dir) not in sys.path:
|
|
sys.path.insert(0, str(parent_dir))
|
|
from ocr.ocr import OCR, TextDetector, TextRecognizer
|
|
from ocr.pdf_parser import SimplePdfParser
|
|
else:
|
|
# 作为模块导入时使用相对导入
|
|
from .ocr import OCR, TextDetector, TextRecognizer
|
|
from .pdf_parser import SimplePdfParser
|
|
|
|
__all__ = ['OCR', 'TextDetector', 'TextRecognizer', 'SimplePdfParser']
|
|
|