Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

from model import OcrHandle #5

Open
Snow670 opened this issue Jul 29, 2024 · 2 comments
Open

from model import OcrHandle #5

Snow670 opened this issue Jul 29, 2024 · 2 comments

Comments

@Snow670
Copy link

Snow670 commented Jul 29, 2024

在pdfocr.py文件中
from model import OcrHandle
项目中并没有这个文件呀,这是需要自己配置嘛?

@NewComer00
Copy link
Owner

NewComer00 commented Aug 1, 2024

以下几行代码用于

  1. chineseocr_lite/目录加入Python解释器的包搜寻路径sys.path末尾
  2. Python解释器最先在chineseocr_lite/目录下寻找到model.py文件(即model模块)并从model模块中引入OcrHandle

# self-defined modules to be added to PYTHONPATH
project_root = os.path.dirname(os.path.abspath(__file__))
ocrlib_path = os.path.join(project_root, 'chineseocr_lite/')
sys.path.append(ocrlib_path)
from model import OcrHandle
# end of self-defined module list

这是chineseocr_lite/model.py文件中OcrHandle的定义处

class OcrHandle(object):
def __init__(self):
self.text_handle = DBNET(model_path)
self.crnn_handle = CRNNHandle(crnn_model_path)
if angle_detect:
self.angle_handle = AngleNetHandle(angle_net_path)
def crnnRecWithBox(self,im, boxes_list,score_list):
"""

我在pdfocr.py脚本中通过动态修改sys.path来引入第三方包和模块,这算是不规范的作法,IDE和LSP也无法正常跟踪这些包或者模块。

正确的方法是把整个仓库chinese-pdf-ocr变成一个Python包,在包配置文件里指定额外的包搜寻路径,然后用户通过pip install -e .安装chinese-pdf-ocrPython包。

很抱歉带来不便,待我找到空闲时做出修改 :-)

@NewComer00 NewComer00 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 1, 2024
@NewComer00 NewComer00 reopened this Aug 1, 2024
@Snow670
Copy link
Author

Snow670 commented Aug 1, 2024

好的,感谢回答

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants