目录
一.配置环境
bash
pip3 install cnocr -i https://pypi.tuna.tsinghua.edu.cn/simple
pip3 install onnxruntime -i https://pypi.tuna.tsinghua.edu.cn/simple
二.应用
2.1常见图片识别
python
from cnocr import CnOcr
img_fp = './input.jpeg'
ocr = CnOcr() # 所有参数都使用默认值
out = ocr.ocr(img_fp)
print(out)
2.2排版简单的印刷体截图图片识别
bash
from cnocr import CnOcr
img_fp = './input.png'
ocr = CnOcr(det_model_name='naive_det')
out = ocr.ocr(img_fp)
print(out)
2.3竖排文字识别
bash
from cnocr import CnOcr
img_fp = './input.png'
ocr = CnOcr(rec_model_name='ch_PP-OCRv3')
out = ocr.ocr(img_fp)
print(out)
2.4英文识别
bash
from cnocr import CnOcr
img_fp = './input.jpeg'
ocr = CnOcr(det_model_name='en_PP-OCRv3_det', rec_model_name='en_PP-OCRv3')
out = ocr.ocr(img_fp)
print(out)
2.5繁体中文识别
bash
from cnocr import CnOcr
img_fp = './input.jpg'
ocr = CnOcr(rec_model_name='chinese_cht_PP-OCRv3') # 识别模型使用繁体识别模型
out = ocr.ocr(img_fp)
print(out)
2.6单行文字的图片识别
bash
from cnocr import CnOcr
img_fp = './input.jpg'
ocr = CnOcr()
out = ocr.ocr_for_single_line(img_fp)
print(out)