PaddleOCR-RPC
Project description
RPC-PaddleOCR
基于 PaddleOCR 部署的 RPC 服务。
提供了一个简单易用的函数 ocr
,通过不同的参数控制返回不同的值。
安装
pip install pdocr-rpc
另外还需要手动安装以下依赖:
客户端依赖
客户端仅需要安装截图工具;
Windows
上使用:
pip3 install pillow
Linux
上使用:
PIL 的 ImageGrab
模块在部分的 Linux
上可能存在问题,报错:ImportError: ImageGrab is macOS and Windows only
;
Linux
上推荐安装 pyscreenshot
;
pip3 install pyscreenshot
服务端依赖
安装 PaddleOCR` 环境
pip3 install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip3 install "paddleocr>=2.0.1" -i https://mirror.baidu.com/pypi/simple
1、使用方法
1.1、导入
from pdocr_rpc import ocr
1.2、使用场景
1.1.1、识别当前屏幕的所有文字内容
ocr()
自动识别当前整个屏幕的所有内容。
1.1.2、指定某张图片识别的所有文字内容
ocr(picture_abspath="~/Desktop/test.png")
返回识别图片 test.png
的内容。
1.1.3、在全屏指定查找某个字符串的坐标
ocr("天天向上")
返回当前屏幕中,“天天向上”的坐标,如果存在多个,则返回一个字典。
1.1.4、指定某张图片查找某个字符串的坐标
ocr("天天向上",picture_abspath="~/Desktop/test.png")
1.3、其他参数
similarity: 匹配度。
return_default: 返回识别的原生数据。
return_first: 只返回第一个,默认为 False,返回识别到的所有数据。
lang: `ch`, `en`, `fr`, `german`, `korean`, `japan`
2.1、启动服务
将 ocr_server.py
文件拷贝到 ocr_env
目录,后台执行它就好了:
cd ocr_env
nohup pipenv run python ocr_server.py &
2.2、配置开机自启
你肯定不想每次机器重启之后都需要手动启动服务,因此我们需要配置开机自启。
写开机自启服务文件:
sudo vim /lib/systemd/system/ocr.service
autoocr
名称你可以自定义,写入以下内容:
[Unit]
Description=OCR Service
After=multi-user.target
[Service]
User=uos
Group=uos
Type=idle
WorkingDirectory=/home/uos/ocr_env
ExecStart=pipenv run python ocr_server.py
[Install]
WantedBy=multi-user.target
注意替换你的${USER}
修改配置文件的权限:
sudo chmod 644 /lib/systemd/system/ocr.service
自启服务生效:
sudo systemctl daemon-reload
sudo systemctl enable ocr.service
查看服务状态:
sudo systemctl status ocr.service
你可以再重启下电脑,看看服务是不是正常启动了,没报错就 OK 了。
2.3、缓存
在 ocr_env/pic
目录下保存了识别的一些缓存图片文件,您可能需要定期进行删除;
当然,你可以使用定时任务对缓存文件进行清理,例如 crontab
、Jenkins
任务等。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pdocr-rpc-1.0.1.tar.gz
(9.2 kB
view hashes)
Built Distribution
pdocr_rpc-1.0.1-py3-none-any.whl
(10.6 kB
view hashes)
Close
Hashes for pdocr_rpc-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | deea162441b5ce371b53f970907d01ab7fdfa987f0940fd62f5e4e8f2f6022ba |
|
MD5 | 18be58845fd678739a5981fba903c3a9 |
|
BLAKE2b-256 | 485c98dc041b8654a90d64be9ca8445a0032d59cf2c60243c046d6453c838b70 |