PPOCRLabel安装和使用

ubuntu系统安装PPOCRLabel两种方式都可以:
1、通过whl包安装与运行

#安装
pip3 install PPOCRLabel
pip3 install trash-cli
#调用
PPOCRLabel --lang ch

2、本地构建whl包并安装, 通过Python脚本运行

#安装
cd PaddleOCR/PPOCRLabel
python3 setup.py bdist_wheel 
pip3 install dist/PPOCRLabel-1.0.2-py2.py3-none-any.whl -i https://mirror.baidu.com/pypi/simple
#调用
cd ./PPOCRLabel  # 切换到PPOCRLabel目录
python PPOCRLabel.py --lang ch

如果顺利,这样就可以之直接用了,但有时候会报下面错误:

QObject::moveToThread: Current thread (0x55fe91ae5490) is not the object's thread (0x55fe91fc6fa0).
Cannot move to target thread (0x55fe91ae5490)
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/mby/anaconda3/envs/paddle_env/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
Available platform plugins are: xcb, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl.
--------------------------------------
C++ Traceback (most recent call last):
--------------------------------------
No stack trace in paddle, may be caused by external reasons.
----------------------
Error Message Summary:
----------------------
FatalError: `Process abort signal` is detected by the operating system.
  [TimeInfo: *** Aborted at 1648220092 (unix time) try "date -d @1648220092" if you are using GNU date ***]
  [SignalInfo: *** SIGABRT (@0x3e80000139a) received by PID 5018 (TID 0x7f18bafe40c0) from PID 5018 ***]

已放弃 (核心已转储)

这种问题官网解决方案,是更改opencv版本,我担心会带来其他问题,所以就换了一种方式。
如果出现这种问题,最好采用第二种安装方式,然后切换到PPOCRLabel目录,找到 PPOCRLabel.py文件,按照下面添加代码,就可以了。
作用呢就是将PPOCRLabel路径下plugins\platforms添加到临时系统环境变量。

__dir__ = os.path.dirname(os.path.abspath(__file__))

import numpy as np
##下面两行是添加的代码,就可以解决上面的问题
plugin_path=os.path.join(__dir__,'plugins','platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']=plugin_path

sys.path.append(__dir__)
sys.path.append(os.path.abspath(os.path.join(__dir__, '../..')))
sys.path.append(os.path.abspath(os.path.join(__dir__, '../PaddleOCR')))
sys.path.append("..")

你可能感兴趣的:(深度学习,python,qt5)