-
检测 + 方向分类器 + 识别全流程
from agentocr import OCRSystem
ocr = OCRSystem(config='ch')
img_path = 'test.jpg'
result = ocr.ocr(img_path, cls=True)
# 结果是一个list,每个item包含了文本框,文字和识别置信度
[[[24.0, 36.0], [304.0, 34.0], [304.0, 72.0], [24.0, 74.0]], ['纯臻营养护发素', 0.964739]]
[[[24.0, 80.0], [172.0, 80.0], [172.0, 104.0], [24.0, 104.0]], ['产品信息/参数', 0.98069626]]
[[[24.0, 109.0], [333.0, 109.0], [333.0, 136.0], [24.0, 136.0]], ['(45元/每公斤,100公斤起订)', 0.9676722]]
......
-
检测 + 识别
from agentocr import OCRSystem
ocr = OCRSystem(config='ch')
img_path = 'test.jpg'
result = ocr.ocr(img_path, cls=False)
# 结果是一个list,每个item包含了文本框,文字和识别置信度
[[[24.0, 36.0], [304.0, 34.0], [304.0, 72.0], [24.0, 74.0]], ['纯臻营养护发素', 0.964739]]
[[[24.0, 80.0], [172.0, 80.0], [172.0, 104.0], [24.0, 104.0]], ['产品信息/参数', 0.98069626]]
[[[24.0, 109.0], [333.0, 109.0], [333.0, 136.0], [24.0, 136.0]], ['(45元/每公斤,100公斤起订)', 0.9676722]]
......
-
方向分类器 + 识别
from agentocr import OCRSystem
ocr = OCRSystem(config='ch')
img_path = 'test.jpg'
result = ocr.ocr(img_path, det=False, cls=True)
# 结果是一个list,每个item只包含识别结果和识别置信度
['韩国小馆', 0.9907421]
-
单独执行检测
from agentocr import OCRSystem
ocr = OCRSystem(config='ch')
img_path = 'test.jpg'
result = ocr.ocr(img_path, rec=False)
# 结果是一个list,每个item只包含文本框
[[26.0, 457.0], [137.0, 457.0], [137.0, 477.0], [26.0, 477.0]]
[[25.0, 425.0], [372.0, 425.0], [372.0, 448.0], [25.0, 448.0]]
[[128.0, 397.0], [273.0, 397.0], [273.0, 414.0], [128.0, 414.0]]
......
-
单独执行识别
from agentocr import OCRSystem
ocr = OCRSystem(config='ch')
img_path = 'test.jpg'
result = ocr.ocr(img_path, det=False)
# 结果是一个list,每个item只包含识别结果和识别置信度
['韩国小馆', 0.9907421]
-
单独执行方向分类器
from agentocr import OCRSystem
ocr = OCRSystem(config='ch')
img_path = 'test.jpg'
result = ocr.ocr(img_path, det=False, cls=True, rec=False)
# 结果是一个list,每个item只包含分类结果和分类置信度
['0', 0.9999924]
-
快速配置:
可通过如下几个选项快速配置不同的模型文件、字典和可视化字体
{
"det_model_dir": "ch_ppocr_mobile_v2.0_det",
"rec_model_dir": "ch_ppocr_mobile_v2.0_rec",
"rec_char_type": "ch",
"rec_char_dict_path": "ppocr_keys_v1",
"vis_font_path": "simfang",
"cls_model_dir": "ch_ppocr_mobile_v2.0_cls"
}
-
完整配置:
详细的参数介绍请参考下一小节的内容
{
"providers": "auto",
"det_algorithm": "DB",
"det_model_dir": "ch_ppocr_mobile_v2.0_det",
"det_limit_side_len": 960,
"det_limit_type": "max",
"det_db_thresh": 0.3,
"det_db_box_thresh": 0.6,
"det_db_unclip_ratio": 1.5,
"use_dilation": false,
"det_db_score_mode": "fast",
"det_east_score_thresh": 0.8,
"det_east_cover_thresh": 0.1,
"det_east_nms_thresh": 0.2,
"det_sast_score_thresh": 0.5,
"det_sast_nms_thresh": 0.2,
"det_sast_polygon": false,
"rec_algorithm": "CRNN",
"rec_model_dir": "ch_ppocr_mobile_v2.0_rec",
"rec_image_shape": "3, 32, 320",
"rec_char_type": "ch",
"rec_batch_num": 8,
"max_text_length": 25,
"rec_char_dict_path": "ppocr_keys_v1",
"use_space_char": true,
"vis_font_path": "simfang",
"drop_score": 0.5,
"cls_model_dir": "ch_ppocr_mobile_v2.0_cls",
"cls_image_shape": "3, 48, 192",
"label_list": ["0", "180"],
"cls_batch_num": 8,
"cls_thresh": 0.9,
"total_process_num": 1,
"show_log": true
}