赞
踩
简易流程: 输入图像 》检测文本 》截取文本 》识别文本 》输出
简单开发一些小工具,这几款ocr库相对使用起来简易;便于简易开发。
pip install paddlepaddle
pip install paddlehub
pip install cnocr
pip install cnstd
pip install easyocr
pip install ddddocr
pip install muggle-ocr -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
单独cnocr模块,只适合打印或文本格式。
import cv2
from cnocr import CnOcr
ocr = CnOcr()
img = './1.jpg'
img = cv2.imread(img)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
res = ocr.ocr(gray)
print(res)
cnstd+cnocr 通用图片中的文字。
from cnstd import CnStd
from cnocr import CnOcr
std = CnStd()
cn_ocr = CnOcr()
box_info_list = std.detect('examples/taobao4.jpg')
for box_info in box_info_list:
cropped_img = box_info['cropped_img'] # 检测出的文本框
ocr_res = cn_ocr.ocr_for_single_line(cropped_img)
print('ocr result: %s' % ''.join(ocr_res))
import easyocr
#指定文字模型
reader = easyocr.Reader(['ch_sim','en'])
res = reader.readtext('./1.jpg')
print(res)
import paddlehub as hub
import cv2
#模型选择
ocr = hub.Module(name="chinese_ocr_db_crnn_mobile")
res = ocr.recognize_text(images=[cv2.imread('./12.jpg')],output_dir='result',visualization=True)
print(res)
import ddddocr
ocr=ddddocr.DdddOcr()
with open('test_img.png', 'rb') as f:
img_bytes=f.read()
res=ocr.classification(img_bytes)
print(res)
# 导入包 import muggle_ocr # 初始化;model_type 包含了 ModelType.OCR/ModelType.Captcha 两种,OCR能识别中文 sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.OCR) with open(r"test1.png", "rb") as f: b = f.read() text = sdk.predict(image_bytes=b) print(text) # ModelType.Captcha 可识别4-6位验证码 sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.Captcha) with open(r"test1.png", "rb") as f: b = f.read() text = sdk.predict(image_bytes=b) print(text)
原图:
easyocr输出:
paddleocr输出:
ddddocr贴张官方图:
https://github.com/breezedeus/cnstd
https://github.com/breezedeus/cnocr
https://github.com/JaidedAI/EasyOCR
https://github.com/PaddlePaddle/PaddleOCR
https://github.com/sml2h3/ddddocr
https://www.cnblogs.com/pythonywy/p/13226330.html
https://pypi.org/project/muggle-ocr/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。