博客
关于我
PaddleOCR数字仪表识别——4. pipeline
阅读量:797 次
发布时间:2023-04-04

本文共 2252 字,大约阅读时间需要 7 分钟。

为了解决在Jupyter Notebook和Streamlit中启动时需要切换到Py37环境的问题,以及PaddleOCR在Streamlit中的兼容性问题,可以按照以下步骤进行:

  • 检查并切换到Py37环境

    • 确保Jupyter Notebook和Streamlit都在Py37的环境下运行。使用以下命令切换到Py37环境:
      conda create -n py37 python=3.7 -yconda activate py37
    • 或者使用虚拟环境:
  • 安装必要的依赖库

    • 安装PaddleOCR和其他相关库:
      pip install paddleocrpip install opencv-pythonpip install numpy
    • 确保安装的版本与当前项目兼容,必要时可以指定版本:
      pip install paddleocr==1.1.0
  • 调整模块导入路径

    • 在Streamlit中,确保PaddleOCR模块的引用路径正确。将以下代码替换为正确的导入方式:
      from paddleocr import PaddleOCRocr = PaddleOCR()
    • 如果问题依旧,可以将PaddleOCR脚本文件移动到项目目录,避免路径冲突。
  • 清理Streamlit缓存

    • 使用Streamlit命令清理缓存:
      streamlit cache clear
    • 重启服务器和浏览器,确保缓存已清除。
  • 检查PaddleOCR版本

    • 确认PaddleOCR版本是否与当前项目兼容。升级到最新版本后,检查是否有新的兼容性问题:
      import paddleocrprint(paddleocr.__version__)
  • 优化预处理步骤

    • 添加预处理代码,确保输入数据符合模型要求:
      import cv2image = cv2.imread("test.jpg")gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)blurred = cv2.GaussianBlur(gray, (5, 5), 0)edged = cv2.Canny(blurred, 50, 200, 255)color = cv2.cvtColor(edged, cv2.COLOR_GRAY2BGR)reverse = cv2.bitwise_not(edged)color = cv2.cvtColor(reverse, cv2.COLOR_GRAY2BGR)
    • 根据实际需要调整预处理参数,确保文字区域清晰可见。
  • 使用inference模型进行推理

    • 将训练好的模型转换为inference模型:
      python3 tools/export_model.py -c configs/rec/rec_icdar15_train.yml -o Global.checkpoints=output/rec_CRNN/best_accuracy Global.save_inference_dir=./inference/rec_crnn/
    • 使用inference模型进行推理,提升速度和效率:
      import paddleocrocr = paddleocr.PaddleOCR()result = ocr.ocr("test.jpg", rec=False)for line in result:    print(line)
  • 处理小数点和非数字字符问题

    • 使用numpy进行索引选择,确保只识别最大的框:
      import numpy as npdef findMaxBox(rsList, num=5):    height = []    for i in rsList:        oneHeight = i[2][1] - i[0][1]        height.append(oneHeight)    nplist = np.array(height)    ind = np.argpartition(nplist, num*(-1))[num*(-1):]    return rsList[ind]
  • 优化模型并使用其他模型

    • 考虑使用其他模型如CTPN和DenseNet + CTC,提升识别准确性:
      from paddleocr import PaddleOCR, draw_ocrocr = PaddleOCR(use_model='CTPN')
  • 改进日志管理

    • 使用subprocess将输出重定向到变量,避免写入磁盘:
      import subprocessresult = subprocess.run("python3 ./PaddleOCR/tools/infer/predict_rec.py --image_dir=\"test.jpg\" --rec_model_dir=./inference/rec_crnn/ --rec_image_shape=\"3, 32, 200\" --rec_char_type=\"ch\" --rec_char_dict_path=./PaddleOCR/ppocr/utils/num_dict.txt", shell=True, capture_output=True, text=True)
  • 通过以上步骤,用户可以有效地解决在Py37环境下使用PaddleOCR和Streamlit时的各种问题,确保开发和部署过程顺利进行。

    转载地址:http://knrfk.baihongyu.com/

    你可能感兴趣的文章
    mysql5.7命令总结
    查看>>
    mysql5.7安装
    查看>>
    mysql5.7性能调优my.ini
    查看>>
    MySQL5.7新增Performance Schema表
    查看>>
    Mysql5.7深入学习 1.MySQL 5.7 中的新增功能
    查看>>
    Webpack 之 basic chunk graph
    查看>>
    Mysql5.7版本单机版my.cnf配置文件
    查看>>
    mysql5.7的安装和Navicat的安装
    查看>>
    mysql5.7示例数据库_Linux MySQL5.7多实例数据库配置
    查看>>
    Mysql8 数据库安装及主从配置 | Spring Cloud 2
    查看>>
    mysql8 配置文件配置group 问题 sql语句group不能使用报错解决 mysql8.X版本的my.cnf配置文件 my.cnf文件 能够使用的my.cnf配置文件
    查看>>
    MySQL8.0.29启动报错Different lower_case_table_names settings for server (‘0‘) and data dictionary (‘1‘)
    查看>>
    MYSQL8.0以上忘记root密码
    查看>>
    Mysql8.0以上重置初始密码的方法
    查看>>
    mysql8.0新特性-自增变量的持久化
    查看>>
    Mysql8.0注意url变更写法
    查看>>
    Mysql8.0的特性
    查看>>
    MySQL8修改密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
    查看>>
    MySQL8修改密码的方法
    查看>>
    Mysql8在Centos上安装后忘记root密码如何重新设置
    查看>>