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])
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()