PaddleOCR提供了docker镜像,建议按官网教程,安装好之后从下面【下载推理模型】接着配置。
这里从头配置了一个环境,也算学习一遍,忽略docker就是paddleOCR ubuntu环境的搭建过程。
获取一个新的ubuntu镜像:
docker pull ubuntu
本机已有一个ubuntu镜像为ubuntu:paddle,新的docker镜像,需要先配置一些基础环境,如net-tools、tar、wget、make、gcc、python3.7等。可自行百度。
创建一个容器:
docker run -it ubuntu:paddle /bin/bash
配置paddleOCR:
cd /home git clone https://github.com/PaddlePaddle/PaddleOCR pip install opencv-python pip install pillow pip install -r requirements.txt python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple pip install paddlehub --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple #返回宿主机下载推理模型,或复制下载地址直接用wget exit
记住CONTAINER ID
拷贝文件到容器中,win+r cmd中执行
docker cp F:\XXX\PaddleOCR\inference 13833b8383eb:/home/PaddleOCR docker start 13833b8383eb docker attach 13833b8383eb
修改params.py文件,文件路径上面下载的模型对应起来:
cd /home/PaddleOCR vim deploy/hubserving/ocr_system/params.py
修改config.json文件,使用CPU:
vim deploy/hubserving/ocr_system/config.json
验证PaddleOCR:
python tools/infer/predict_system.py --image_dir="./doc/imgs/1.jpg" --det_model_dir="./inference/ch_ppocr_server_v2.0_det_infer/" --rec_model_dir="./inference/ch_ppocr_server_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
CPU4.67秒,速度还可以
启动服务:
hub install deploy/hubserving/ocr_system
hub serving start -c "/home/PaddleOCR/deploy/hubserving/ocr_system/config.json"
出现地址服务启动成功:
至此,PaddleOCR环境搭建完成。
下面docker服务配置:
在/home/PaddleOCR新建脚本文件paddleOCRServer
#!/bin/sh cd /home/PaddleOCR hub install /home/PaddleOCR/deploy/hubserving/ocr_system hub serving start -c "/home/PaddleOCR/deploy/hubserving/ocr_system/config.json"
修改权限:
chmod 777 paddleOCRServer
一切配置好后,更新一下镜像:
docker commit -m="has update" -a="myname" 13833b8383eb ubuntu:paddle
docker端口映射到宿主机,创建一个名为paddleocr的新的容器,宿主机cmd终端执行:
docker run --name paddleocr -it -p 8868:8868 ubuntu:paddle /home/PaddleOCR/paddleOCRServer
下次可根据名字直接打开容器:
docker start paddleocr docker attach paddleocr
Qt调用:
// URL QString baseUrl = "http://127.0.0.1:8868/predict/ocr_system"; // 构造请求 QNetworkRequest request; request.setUrl(QUrl(baseUrl)); request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/json")); QNetworkAccessManager *manager = new QNetworkAccessManager(this); // 发送请求 QNetworkReply *pReplay = manager->post(request, data); // 局部的事件循环,等待响应结束 QEventLoop eventLoop; QObject::connect(manager, &QNetworkAccessManager::finished, &eventLoop, &QEventLoop::quit); eventLoop.exec(); // 返回信息 QByteArray bytes = pReplay->readAll(); QString string = QString::fromUtf8(bytes); qDebug() << string; QJsonObject resultJson = QJson::getJsonObjectFromString(string); QJsonArray resArr = resultJson.take("results")[0].toArray(); for each (auto var in resArr) { qDebug() << var.toObject().take("text").toString(); }
Docker教程:
#查看正在运行的容器 docker ps #查看所有容器 docker ps -a #查看镜像 docker images #删除容器 docker rm id #删除镜像 docker rmi id
原文链接:https://blog.csdn.net/dongjuexk/article/details/120965160?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522171836884016800178552552%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=171836884016800178552552&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-11-120965160-null-null.nonecase&utm_term=docker%E9%83%A8%E7%BD%B2