PaddleOCR搭建
PaddleOCR搭建

PaddleOCR搭建

新版教程

https://gitee.com/paddlepaddle/Serving/blob/develop/doc/Windows_Tutorial_CN.md

搭建conda虚拟环境(可能会有问题,不建议) ↓ 参考文章

//创建PaddleOCR的环境
conda create -n PaddleOCR python=3.8

//进入环境
conda activate PaddleOCR 

//安装PaddleHub
pip install -r D:/Desktop/PaddleOCR/requirements.txt
pip install PaddleHub

hub install D:/Desktop/PaddleOCR/deploy/hubserving/ocr_system/

前期环境步骤同↓文章

3.安装paddlehub

pip install paddlehub

4.clone PaddleOCR

//clone 源码
git clone https://github.com/PaddlePaddle/PaddleOCR.git

或使用镜像站
git clone https://api.mtr.pub/PaddlePaddle/PaddleOCR.git
git clone https://ghproxy.fsofso.com/https://github.com/PaddlePaddle/PaddleOCR.git
git clone https://hub.fastgit.xyz/PaddlePaddle/PaddleOCR.git

5.模型下载 https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.4/README_ch.md

6个模型选同一行三个下载即可
//以 中英文超轻量PP-OCRv2模型(13.0M) 为例
//在  PaddleOCR  目录下新建  inference  目录
//inference  目录下 cmd 运行 wget
wget --no-check-certificate https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_det_infer.tar
wget --no-check-certificate https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar
wget --no-check-certificate https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/ch_PP-OCRv2_rec_infer.tar

下载解压后目录长这样

6.修改运行时的模型

cfg.det_model_dir = "./inference/ch_PP-OCRv2_det_infer/"
cfg.rec_model_dir = "./inference/ch_PP-OCRv2_det_infer/"
cfg.cls_model_dir = "./inference/ch_ppocr_mobile_v2.0_cls_infer/"

改成你下的模型的名称即可,按步骤4操作的话无需修改
部署服务名服务类型路径
ocr_system预测(det)+识别(rec)./PaddleOCR/deploy/hubserving/ocr_system/params.py
ocr_det预测./PaddleOCR/deploy/hubserving/ocr_det/params.py
ocr_rec识别./PaddleOCR/deploy/hubserving/ocr_rec/params.py

7.注册服务

安装检测服务模块:
hub install deploy/hubserving/ocr_det/

安装识别服务模块:
hub install deploy/hubserving/ocr_rec/

安装检测+识别串联服务模块:
hub install deploy/hubserving/ocr_system/

8.运行

//基于127.0.0.1:8866启用串联服务
//网址: http://127.0.0.1:8866/predict/ocr_system
hub serving start -m ocr_system -p 8866

/基于127.0.0.1:8866启用识别服务
//网址: http://127.0.0.1:8866/predict/ocr_rec
hub serving start -m ocr_rec -p 8865

/基于127.0.0.1:8866启用预测服务
//网址: http://127.0.0.1:8866/predict/ocr_det
hub serving start -m ocr_det -p 8864

附按键代码

Import "Cjson.lua"
Import "zm.luae"
Dim data="{""images"": ["""&zm.FileReadBinaryBase64("/sdcard/pictures/1.png")&"""]}"
For Each urls In Array("http://你的ip:8866/predict/ocr_system","http://你的ip:8865/predict/ocr_rec","http://你的ip:8864/predict/ocr_det")
    Dim t={"url":urls,"data":data, "header":{"Content-Type":"application/json"}}
    Dim 返回值 = Url.HttpPost(t)
    TracePrint 返回值
    Dim ta=Cjson.Decode(返回值)
    Dim tt=ta["results"][1]
    TracePrint Cjson.Encode(tt)
    For Each v In tt
        If v["text"] <> null Then 
            TracePrint v["text"]
        End If
        If v["text_region"] <> null Then 
            TracePrint "x1,y1|"&zm.VarInfo(v["text_region"][1]) &"   x2,y2|"&zm.VarInfo(v["text_region"][3])
        End If
    Next

Next

PS:

0.python-Levenshtein安装失败|onnx无法安装

使用whl包安装

https://www.lfd.uci.edu/~gohlke/pythonlibs/#python-levenshtein

通用逻辑:

https://www.lfd.uci.edu/~gohlke/pythonlibs/#

https://pypi.org/

下载对应的whl包(xxxx-cp(py版本号))安装

pip install xxxxx.whl

或是对症下药安装vc++2015全量编译器和cmaker(不建议,会头大)

pip install numpy
pip install protobuf
pip install cmaker