赞
踩
1.设置pip数据源
在c:\user\用户名 目录中创建pip目录,在目录里新建pip.ini文件,输入以下内容:
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
2.升级pip至23
查看当前版本
pip show pip
升级
python -m pip install --upgrade pip
验证升级成功
pip show pip
3.安装
安装paddle。这个安装就按百度官网的来,不要验证是不是安装正确,只要不报错就正确,因为网上有一个验证的方法老是过不去,卡了好长时间,其实随着paddle的升级,验证方法也会改变。
#执行以下命令安装(推荐使用百度源)
python -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
#或
python -m pip install paddlepaddle -i https://pypi.tuna.tsinghua.edu.cn/simple
git clone paddleOCR项目,这个项目其实就是在百度飞桨的基础上研发的一个套件而已。
#推荐
git clone https://github.com/PaddlePaddle/PaddleOCR
#因为网络问题无法pull成功,也可选择使用码云上的托管, 码云托管代码可能无法实时同步本github项目更新,存在3~5天延时,请优先使用推荐方式
git clone https://gitee.com/paddlepaddle/PaddleOCR
下载后安装
cd PaddleOCR
python -m pip install -r requirements.txt
(1)安装报错 - lanms-neo
Building wheel for lanms-neo (pyproject.toml) ... error
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
解决方式
安装Microsoft Visual C++14.0或更高版本
https://visualstudio.microsoft.com/visual-cpp-build-tools/
下载:Microsoft C++ 生成工具(vs_BuildTools.exe)
(2)安装报错 - protobuf版本不在3.1.0 ~ 3.20.0之间
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
paddlepaddle 2.4.1 requires protobuf<=3.20.0,>=3.1.0, but you have protobuf 3.20.3 which is incompatible.
解决方式
卸载protobuf 已经安装的版本
pip uninstall protobuf
安装3.19.0版本
pip install protobuf==3.19.0
再进行paddle环境的验证吧:
import paddle
paddle.utils.run_check()
ocr解析 - cmd
# 预测image_dir指定的单张图像
python tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_PP-OCRv3_det_infer/" --rec_model_dir="./inference/ch_PP-OCRv3_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True
# 预测image_dir指定的图像集合
python tools/infer/predict_system.py --image_dir="./doc/imgs/" --det_model_dir="./inference/ch_PP-OCRv3_det_infer/" --rec_model_dir="./inference/ch_PP-OCRv3_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True
# 如果想使用CPU进行预测,需设置use_gpu参数为False
python tools/infer/predict_system.py --image_dir="./doc/imgs/11.jpg" --det_model_dir="./inference/ch_PP-OCRv3_det_infer/" --rec_model_dir="./inference/ch_PP-OCRv3_rec_infer/" --cls_model_dir="./inference/ch_ppocr_mobile_v2.0_cls_infer/" --use_angle_cls=True --use_space_char=True --use_gpu=False
ocr解析 - python代码
from paddleocr import PaddleOCR, draw_ocr
if __name__ == "__main__":
print(111)
ocr = PaddleOCR(use_angle_cls=True, lang="ch") # need to run only once to download and load model into memory
img_path = 'C:/Users/xx/Desktop/2a17a3ee-5407-11ed-a5b8-a33fa7d34a36.pdf_/0.png'
# ocr解析
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line)
# 显示结果
# 如果本地没有simfang.ttf,可以在doc/fonts目录下下载
from PIL import Image
result = result[0]
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='C:/Users/xxx/Desktop/2a17a3ee-5407-11ed-a5b8-a33fa7d34a36.pdf_/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('C:/Users/xxx/Desktop/2a17a3ee-5407-11ed-a5b8-a33fa7d34a36.pdf_/result.jpg')
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。