【OCR】OCR学习记录(4)

百度开源的PaddleOCR项目
地址:https://github.com/PaddlePaddle/PaddleOCR

1、介绍

  • 在PaddleOCR识别中,会依次完成三种任务:检测、方向分类、文本识别

  • 关于预训练权重,PaddleOCR官网根据提供权重文件大小分为两类:
    一类为轻量级,(检测+分类+识别)三类权重加起来大小一共才9.4MB,适用于手机端和服务器部署;
    另一类(检测+分类+识别)三类权重加起来一共143.4MB,适用于服务器部署。(无论模型是否为轻量级,识别效果都能与商业效果相比。)

  • 支持多语言识别,目前能够支持80多种语言;

  • 除了能对中文、英语、数字识别之外,还能应对字体倾斜、文本中含有小数点字符等复杂情况;

  • 提供丰富的OCR领域相关工具供我们使用,方便我们制作自己的数据集、用于训练
    半自动数据标注工具;
    数据合成工具;

  • 支持pip安装,简单上手

2、使用

2.1 环境

python:3.8.8
os:linux
GCC:7.3.0
appdirs               1.4.4
astor                 0.8.1
Babel                 2.9.0
bce-python-sdk        0.8.59
certifi               2020.12.5
cfgv                  3.2.0
chardet               4.0.0
click                 7.1.2
cycler                0.10.0
Cython                3.0a6
decorator             4.4.2
distlib               0.3.1
filelock              3.0.12
flake8                3.9.0
Flask                 1.1.2
Flask-Babel           2.0.0
future                0.18.2
gast                  0.4.0
identify              2.1.3
idna                  2.10
imageio               2.9.0
imgaug                0.4.0
itsdangerous          1.1.0
Jinja2                2.11.3
kiwisolver            1.3.1
lmdb                  1.1.1
MarkupSafe            1.1.1
matplotlib            3.3.4
mccabe                0.6.1
networkx              2.5
nodeenv               1.5.0
numpy                 1.20.1
opencv-contrib-python 4.5.1.48
opencv-python         4.2.0.32
paddledet             2.0.1
paddleocr             2.0.2
paddlepaddle-gpu      2.0.1.post101
Pillow                8.1.2
pip                   21.0.1
pre-commit            2.11.1
protobuf              3.15.6
psutil                5.8.0
pyclipper             1.2.1
pycocotools           2.0.2
pycodestyle           2.7.0
pycryptodome          3.10.1
pyflakes              2.3.0
pyparsing             2.4.7
PyQt5                 5.15.4
PyQt5-Qt5             5.15.2
PyQt5-sip             12.8.1
python-dateutil       2.8.1
python-Levenshtein    0.12.2
pytz                  2021.1
PyWavelets            1.1.1
PyYAML                5.4.1
requests              2.25.1
scikit-image          0.17.2
scipy                 1.6.1
setuptools            52.0.0.post20210125
Shapely               1.7.1
shellcheck-py         0.7.1.1
six                   1.15.0
terminaltables        3.1.0
tifffile              2021.3.5
toml                  0.10.2
tqdm                  4.59.0
trash-cli             0.20.12.26
typeguard             2.12.0
urllib3               1.26.3
virtualenv            20.4.2
visualdl              2.1.1
Werkzeug              1.0.1
wheel                 0.36.2

2.2 安装PaddlePaddle2.0
PaddleOCR 需在 PaddlePaddle2.0 下才可以正常运行,开始之前请确保 PaddlePaddle2.0 已经安装

pip install paddlepaddle-gpu==2.0.1.post101

环境都配置完毕后,clone项目:
下载解压,上传服务器
https://github.com/PaddlePaddle/PaddleOCR
在这里插入图片描述
新建一个inference文件夹:

mkdir inference && cd inference

下载(检测+分类+识别)权重放入inference文件夹,并解压

下载:
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_det_infer.tar
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar
解压:
tar xf  ch_ppocr_mobile_v2.0_det_infer.tar
tar xf  ch_ppocr_mobile_v2.0_cls_infer.tar
tar xf  ch_ppocr_mobile_v2.0_rec_infer.tar

inference文件夹:
在这里插入图片描述
2.3 PaddleOCR使用
以上环境配置好之后,就可以使用 PaddleOCR 进行识别了,在PaddleOCR 项目环境下打开终端,根据自己情况,输入下面三种类型中的一种即可完成文本识别。

2.3.1 使用GPU,识别单张图片

python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True

2.3.2 使用GPU,识别多张图片

python3 tools/infer/predict_system.py --image_dir="./doc/imgs/" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True

2.3.3 不使用GPU,识别单张图片

python3 tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_ppocr_mobile_v2.0_det_infer/"  --rec_model_dir="./inference/ch_ppocr_mobile_v2.0_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True --use_gpu=False

里面有两个参数需要自己配置一下,参数说明:

  • image_dir : 为需要识别图片路径或文件夹;
  • det_model_dir :存放识别后图片路径或文件夹;

PaddleOCR 识别一张图片很快,只用 CPU 的话,也只需要两三秒。

小结:
Paddle-OCR 属于Paddle 框架其中的一个应用,Paddle 除了 OCR 之外还有许多其它好玩的模型,关键开发者提供有训练好的预权重文件、降低了使用门槛。

参考:
https://zhuanlan.zhihu.com/p/380142530

猜你喜欢

转载自blog.csdn.net/AugustMe/article/details/120652160
OCR