侧边栏壁纸
博主头像
学海无涯博主等级

学无止境

  • 累计撰写 321 篇文章
  • 累计创建 80 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

PaddleOCR安装及使用

利刃
2022-09-14 / 0 评论 / 0 点赞 / 5 阅读 / 3426 字
温馨提示:
本文最后更新于 2024-08-13,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

概述

在项目中,需要用到OCR识别,经过搜索,决定使用PaddleOCR.

安装

1、安装paddlepaddle 访问官网:https://www.paddlepaddle.org.cn/ 根据自己机器的情况,选择相对应的安装方式。
image   Linux&&Windows使用pip安装方式是一致的。
python -m pip install paddlepaddle==2.3.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
image   2、安装paddleocr
pip install paddleocr -i https://mirror.baidu.com/pypi/simple
image 3、识别代码
# 导入相关包
from paddleocr import PaddleOCR, paddleocr, draw_ocr
#  定义ocr
ocr = PaddleOCR(se_angle_cls=False, lang="ch", det_model_dir="./inference/det/",
                        rec_model_dir="./inference/rec/",
                        enable_mkldnn=True,use_tensorrt=True,use_angle_cls=False)

# 通过paddleocr将图片中的文本转换
def ocr_To_Text(Img):
    # 识别到的文本以列表形式存储至变量
    result = ocr.ocr(Img, cls=False)
    # 对图片进行标识
    from PIL import Image
    image = Image.open(Img).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='./fonts/simfang.ttf')
    im_show = Image.fromarray(im_show)
    # 保存识别后的图片
    im_show.save('result.jpg')

ocr_To_Text('.\行程码模板.jpg')
  4、识别结果 paddleocr识别到的数据结果是一个list,每个item包含了文本框,文字和识别置信度。每条数据内容如下: image 输出的result.jpg图片效果如下: image
0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区