pycharm运行PaddleOCR

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')
  • 2
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
要在PyCharm中安装PaddleOCR,您需要按照以下步骤进行操作: 1. 首先,确保您已经在您的计算机上安装了PyCharm IDE。如果没有,请前往PyCharm官方网站下载并安装最新版本的PyCharm。 2. 打开PyCharm,并创建一个新的项目或打开您已有的项目。 3. 在PyCharm的顶部菜单栏中,选择“File(文件)”>“Settings(设置)”(在Windows上可能是“File(文件)”>“Settings(设置)”)。 4. 在设置窗口中,选择左侧的“Project(项目)”>“Python Interpreter(Python解释器)”。 5. 在右侧的Python解释器列表中,点击加号按钮“+”来添加一个新的解释器。 6. 在弹出的窗口中,选择“Existing environment(现有环境)”选项,并浏览到您的PaddleOCR项目所在的文件夹。 7. 选择正确的Python解释器,并点击“OK(确定)”按钮。 8. 等待PyCharm安装和配置PaddleOCR的必需依赖项。 9. 一旦安装完成,您就可以在PyCharm中使用PaddleOCR了。 请注意,您提供的引用、和是指您计算机上的文件路径,并不直接与PaddleOCR的安装过程相关。因此,在安装PaddleOCR时,您不需要直接引用这些文件路径。相反,您只需要按照上述步骤在PyCharm中配置正确的Python解释器,并安装PaddleOCR的依赖项即可。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Python:paddleocr库安装及使用补充(20220406更新)](https://blog.csdn.net/Fan_shine/article/details/123089196)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值