光学字符检测与识别技术(2)

安装CnOCR

1
pip install cnocr

python3.11无法安装onnxruntime可以执行如下命令

1
pip install --extra-index-url https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/pypi/simple/ ort_nightly==1.15.0.dev20230412001

使用CnOCR

1
2
3
4
5
6
7
8
9
10
11
12
13
from cnocr import CnOcr

imgpath = '20211112134535.png'

ocr = CnOcr(
det_model_backend='pytorch',
det_model_name='db_resnet34',
rec_model_backend='pytorch',
rec_model_name='densenet_lite_136-fc',
box_score_thresh='0.25',
)

result = ocr.ocr(f'{imgpath}')

竖排文字识别

1
2
3
4
5
6
7
8
9
from cnocr import CnOcr

imgpath = '20211112134535.png'

ocr = CnOcr(
rec_model_name='ch_PP-OCRv3'
)

result = ocr.ocr(f'{imgpath}')

演示系统
可用模型