paddlepaddle(一)文字识别

2.1 CPU版的PaddlePaddle

python -m pip install paddlepaddle==2.2.2 -i https://mirror.baidu.com/pypi/simple

2.2 GPU版的PaddlePaddle

2.2.2 CUDA10.1的PaddlePaddle

python -m pip install paddlepaddle-gpu==2.2.2.post101 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html
2.2.2 CUDA10.2的PaddlePaddle

python -m pip install paddlepaddle-gpu==2.2.2 -i https://mirror.baidu.com/pypi/simple
2.2.3 CUDA11.0的PaddlePaddle

python -m pip install paddlepaddle-gpu==2.2.2.post110 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html
2.2.4 CUDA11.1的PaddlePaddle

python -m pip install paddlepaddle-gpu==2.2.2.post111 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html
2.2.5 CUDA11.2的PaddlePaddle

python -m pip install paddlepaddle-gpu==2.2.2.post112 -f https://www.paddlepaddle.org.cn/whl/windows/mkl/avx/stable.html

安装paddle:

在pycharm输入:pip install paddle -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

需要按要求安装common、dual、tight、data、prox模块

可以直接使用pip安装PaddleOCR库。

pip install paddleocr

from paddleocr import PaddleOCR, draw_ocr
# 模型路径下必须含有model和params文件

# -*- coding:utf-8 -*-
# @Time
# @Author: WangBenYan

import pandas
from paddleocr import PaddleOCR, draw_ocr
# 显示结果
from PIL import Image
from pandas import DataFrame
# 模型路径下必须含有model和params文件
ocr = PaddleOCR(use_angle_cls=True,
                use_gpu=False)
# det_model_dir='{your_det_model_dir}', rec_model_dir='{your_rec_model_dir}',
# rec_char_dict_path='{your_rec_char_dict_path}', cls_model_dir='{your_cls_model_dir}', use_angle_cls=True
img_path = 'C:\\Users\\Administrator\\Desktop\\5.png'
# img_path = 'C:\\Users\\Administrator\\Desktop\\3.jpg'
# img_path = 'C:\\Users\\Administrator\\Desktop\\denggao.png'
result = ocr.ocr(img_path, cls=True)
for line in result:
    # print(line)
    # print(str(line[0][3][0]))

    # boxes = [line[0] for line in result]
    # print(boxes)
    print([line[1][0]])
    # txts = [line[1][0] for line in result]
    # print(txts)
    # scores = [line[1][1] for line in result]
    # print(scores)


# 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='D:/paddle_pp/PaddleOCR/doc/simfang.ttf')
# im_show = Image.fromarray(im_show)
# im_show.save('result.jpg')  # 结果图片保存在代码同级文件夹中。


 
# 显示结果
from PIL import Image
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='D:/paddle_pp/PaddleOCR/doc/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg') #结果图片保存在代码同级文件夹中。

-- 简单测试代码

paddleocr 是一个十分好的开源项目,可以搭配OpenCv 根据自己实际项目的图像获取拉平处理,再OCR可以实现精准识别

from paddleocr import PaddleOCR
ocr=PaddleOCR(use_angle_cls = True,use_gpu= False) #使用CPU预加载,不用GPU
text=ocr.ocr("test.png",cls=True)                     #打开图片文件
#打印所有文本信息
for t in text:
    print(t[1][0])

【OCR 文字识别】Python中一个不错的OCR库-EasyOCR

pip install easyocr

import easyocr
reader = easyocr.Reader(['ch_sim','en'])
result = reader.readtext('test.png')

如果你的电脑没有GPU或者显存不足,可以加一个gpu=false的参数仅使用CPU运行:

reader = easyocr.Reader(['ch_sim','en'], gpu = False)

#test

ocr = PaddleOCR(use_angle_cls=True, use_gpu=False)  # 使用CPU预加载,不用GPU
text = ocr.ocr(img, cls=True)
result = str(text[0][1][0]).replace('车牌号码:', '').upper()
 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值