当前位置:   article > 正文

pycharm运行PaddleOCR_paddlepaddle 2.4.1 requires protobuf<=3.20.0,>=3.1

paddlepaddle 2.4.1 requires protobuf<=3.20.0,>=3.1.0, but you have protobuf

1.设置pip数据源
在c:\user\用户名 目录中创建pip目录,在目录里新建pip.ini文件,输入以下内容:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = mirrors.aliyun.com
  • 1
  • 2
  • 3
  • 4

2.升级pip至23
查看当前版本

pip show pip
  • 1

升级

python -m pip install --upgrade pip
  • 1

验证升级成功

pip show pip
  • 1

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
  • 1
  • 2
  • 3
  • 4

git clone paddleOCR项目,这个项目其实就是在百度飞桨的基础上研发的一个套件而已。

#推荐
git clone https://github.com/PaddlePaddle/PaddleOCR
#因为网络问题无法pull成功,也可选择使用码云上的托管, 码云托管代码可能无法实时同步本github项目更新,存在3~5天延时,请优先使用推荐方式
git clone https://gitee.com/paddlepaddle/PaddleOCR
  • 1
  • 2
  • 3
  • 4

下载后安装

cd PaddleOCR
python -m pip install -r requirements.txt
  • 1
  • 2

(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/
  • 1
  • 2

解决方式
安装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.
  • 1
  • 2

解决方式
卸载protobuf 已经安装的版本

pip uninstall protobuf
  • 1

安装3.19.0版本

pip install protobuf==3.19.0
  • 1

再进行paddle环境的验证吧:

import paddle
paddle.utils.run_check()
  • 1
  • 2

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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

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')
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/692744
推荐阅读
相关标签
  

闽ICP备14008679号