栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

paddleocr快速使用部署流程cpu版本

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

paddleocr快速使用部署流程cpu版本

1.环境部署
创建虚拟环境
conda create -n videoOCR_CPU python=3.8

激活虚拟环境
conda activate videoOCR_CPU

升级pip
python -m pip install --upgrade pip

安装paddle(参考https://www.paddlepaddle.org.cn/documentation/docs/zh/install/conda/windows-conda.html#anchor-0)
conda install paddlepaddle==2.2.2 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/Paddle/

安装shapely(仅windows)
在https://www.lfd.uci.edu/~gohlke/pythonlibs/#shapely下载对应python版本的shapely
将下载文件复制到 anaconda/envs/videoOCR_CPU/libs文件夹下,并在cmd中cd到此文件夹,使用pip安装whl
pip install Shapely‑1.7.1‑cp38‑cp38‑win_amd64.whl(换成对应下载的whl,根据python版本进行下载)

安装paddleocr
pip install "paddleocr>=2.0.1" # 推荐使用2.0.1+版本
2.官方源码
from paddleocr import PaddleOCR, draw_ocr

# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True, lang="ch")  # need to run only once to download and load model into memory
img_path = 'img_test.jpg'
result = ocr.ocr(img_path, cls=True)
for line in result:
    print("输出:",line[1])

# 显示结果
from PIL import Image

image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='./fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('img_test.jpg')
3.模型更改
ocr = PaddleOCR(det_model_dir='E:\work\python\OCR\inference\ch_ppocr_mobile_v2.0_det_infer\', 
rec_model_dir='E:\work\paddle_train\PaddleOCR\inference\rec_crnn\', rec_char_dict_path='E:\work\paddle\PaddleOCR-release-2.4\ppocr\utils\ppocr_keys_v1.txt',
cls_model_dir='E:\work\python\OCR\inference\ch_ppocr_mobile_v2.0_cls_infer\',
                use_angle_cls=True)
4.愉快的进行应用啦!!!
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/858553.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号