1.首先下载并安装python3.7.8 64位,系统是win10 64位
注:安装时Add path勾选
2.进入命令提示符界面
3.升级pip版本
python -m pip install --upgrade pip
4.安装PaddlePaddle
python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
5.检查PaddlePaddle是否成功
python import paddle.fluid as fluid fluid.install_check.run_check()
出现Your Paddle Fluid is installed successfully! Let's start deep Learning with Paddle Fluid now,表示安装成功
6.下载 自己搜索一下安装包,可先用pip list查看一下是否安装过
7.拷贝shapely安装包到Python安装目录下的libs文件夹
进入该目录后,执行
pip install Shapely-1.8.1.post1-cp38-cp38-win_amd64.whl
8.使用git工具下载运行库
git clone https://github.com/PaddlePaddle/PaddleOCR
或者:
git clone https://gitee.com/paddlepaddle/PaddleOCR
9.进入下载库PaddleOCR文件夹,安装第三方依赖项
python -m pip install -r requirements.txt
10.下载训练库,权重文件
ch_ppocr_mobile_v2.0_rec_infer.tar-识别权重
ch_ppocr_mobile_v2.0_cls_infer.tar-方向分类权重
ch_ppocr_mobile_v2.0_det_infer.tar-检测权重
下载到本地之后分别进行解压,创建一个 inference 文件夹,把前面解压后的三个文件夹放入 inference 中,再把 inference 文件夹放入 PaddleOCR 中,最终树形目录结构效果如下:
11.测试实例
python 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
(1)问题没有模块:cv2,解决:
pip install opencv-python -i https://mirror.baidu.com/pypi/simple
(2)问题没有模块:skimage,解决:到网站
https://www.lfd.uci.edu/~gohlke/pythonlibs/
下载scikit_image-0.19.2-cp38-cp38-win_amd64.whl(注意cp38与python3.8对应)
(3)其他缺少的模块,一般直接安装pip install 模块名称 即可解决
以上环境配置好之后,就可以使用 PaddleOCR 进行识别了,在PaddleOCR 项目环境下打开终端,根据自己情况,输入下面三种类型中的一种即可完成文本识别
<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>使用 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
<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 的话,也只需要两三秒
12.显示结果