根据官方gitee仓库Readme总结:
https://gitee.com/paddlepaddle/PaddleOCR/
Windows下配置Anaconda环境
- 官方下载地址:https://www.anaconda.com/download/success
- 下载完成后默认安装即可。
- 打开
Anoconda Prompt
命令行工具
- 命令安装
# 使用清华源创建 ml_env环境
conda create --name ml_env python=3.8 --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
# 使用环境
conda activate ml_env
# CPU 版 paddle
pip install paddlepaddle -i https://pypi.tuna.tsinghua.edu.cn/simple
# GPU 版 paddle
pip install paddlepaddle-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple
# paddleocr工具包
pip install paddleocr -i https://pypi.tuna.tsinghua.edu.cn/simple
Pycharm使用创建的Anaconda环境
conda info
查看环境路径
- 打开pycharm设置,搜索
Python Interpreter
,show all
等如图操作
- 找到安装的
ml_env
运行环境目录
- 选择后应用即可。
使用PaddleOCR 提取文字
图片可自行准备
from paddleocr import PaddleOCR, draw_ocr
from PIL import Image
# paddleocr目前支持中英文、英文、法语、德语、韩语、日语等80个语种,可以通过修改lang参数进行切换
ocr = PaddleOCR(use_angle_cls=False, lang="ch") # need to run only once to download and load model into memory
img_path = "./test_img/hetong2.jpg"
result = ocr.ocr(img_path, cls=False)
line = []
for line in result:
result = line
# 可视化结果
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='./simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.show()
运行后如图: