赞
踩
1.升级pip
python -m pip install --upgrade pip
2.跟着官网快速安装深度学习框架--paddlepaddle,我安装的是cpu版本
开始使用_飞桨-源于产业实践的开源深度学习平台 (paddlepaddle.org.cn)
3.git paddleocr套件
git clone https://github.com/PaddlePaddle/PaddleOCR.git
4.下载完毕进入PaddleOCR文件夹,并安装
- cd PaddleOCR
- python -m pip install -r requirements.txt
- 或采用镜像
- pip install -r requirments.txt -i https://mirror.baidu.com/pypi/simple
-
PS:可能会报找不到文件的错误
Could not open requirements file: [Errno 2] No such file or directory: 'requirments.txt'
解决办法:跟着网上的教程,重新安装依赖库--shapely
- #卸载Shapely
- pip uninstall shapely
-
- #重新安装Shapely
- pip install Shapely-1.7.1-cp37-cp37m-win_amd64.whl
-
- #重新安装
- pip install -r requirements.txt
- pip install -i https://pypi.tuna.tsinghua.edu.cn/simple paddleocr
又报错了,提示要求protobuf版本要低于3.20.2,高于3.1.0,这个可以不管,因为后续又报错了
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This be
haviour is the source of the following dependency conflicts.
paddlepaddle 2.5.1 requires protobuf<=3.20.2,>=3.1.0; platform_system == "Windows", but you have protobuf 4.24.2 w
hich is incompatible.
解决办法:重新安装即可,安装大于等于3.19.0的版本,不然可能会遇到以下错误
pip install protobuf==3.19.0
5.测试安装是否成功
(1)查看官方测试代码
PaddleOCR/doc/doc_ch/whl.md at static · PaddlePaddle/PaddleOCR · GitHub
(2)查看图片
- import matplotlib.pyplot as plt
- from PIL import Image
-
- ## 显示原图,读取名称为1.jpg的测试图像
- img_path= "./photo/1.jpg"
- img = Image.open(img_path)
- plt.figure("test_img", figsize=(10,10))
- plt.imshow(img)
- plt.show()
通过该笔者写法解决draw_ocr出错问题:
paddleOCR中示例draw_ocr出错问题解决_Blackrosetian的博客-CSDN博客
- from paddleocr import PaddleOCR, draw_ocr
-
- # Paddleocr目前支持中英文、英文、法语、德语、韩语、日语,可以通过修改lang参数进行切换
- # 参数依次为`ch`, `en`, `french`, `german`, `korean`, `japan`。
- ocr = PaddleOCR(use_angle_cls=True, lang="ch") # need to run only once to download and load model into memory
- result = ocr.ocr(img_path, cls=True)
- for line in result:
- print(line)
-
- # 显示结果
- from PIL import Image
- image = Image.open(img_path).convert('RGB')
- boxes = [detection[0] for line in result for detection in line] # Nested loop added
- txts = [detection[1][0] for line in result for detection in line] # Nested loop added
- scores = [detection[1][1] for line in result for detection in line] # Nested loop added
- im_show = draw_ocr(image, boxes, txts, scores)
- im_show = Image.fromarray(im_show)
得到识别结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。