1 基础知识
1.1 软件简介
PaddleOCR旨在打造一套丰富、领先、实用的OCR工具库
PaddleOCR助力开发者训练出更好的模型,并应用落地
1.2 应用场景
– 金融场景(表单识别、票据识别)
– 工业场景(电表度数识别、车牌识别)
– 教育场景(手写识别、公式识别)
– 医疗场景(化验单识别)
1.3 训练部署
– 训练方式(单机训练、分布式训练、混合精度训练)
– 训练环境(Linux GPU/CPU、Linux DCU、Windows GPU/CPU、macOS)
– 模型压缩(剪枝、量化、蒸馏)
– 推理部署方式(Python/C++推理、Python/C++Serving服务化部署、openCL ARM GPU、Paddle2ONNX、ARM CPU Jetson、Paddle.js、云上飞桨)
1.4 产业级特色模型
1.4.1 PP-OCR(超轻量OCR系统)
– PP-OCRv4,检测+方向分类+识别=14.6M
– 英文数字模型,专注提升纯英文数据场景效果
– 多语言模型,支持韩语、日语、德语、法语等约80种语言
1.4.2 PP-Structure(智能文档分析系统)
– 支持版面分析
– 支持表格识别(含Excel导出)
– 支持关键信息抽取
– 支持版面复原
– 支持PDF转Word
1.4.3 PP-ChatOCR(通用信息提取系统)
– 基于LLMs的信息抽取
– 支持通用信息提取
– 支持指令微调
1.5 前沿算法
– 文本检测(EAST、DB、SAST、PSENet、FCENet等)
– 文本识别(CRNN、SRN、NRTR、SVTR、ABINet等)
– 端到端(PGNet)
– 版面分析(Layoutparser、PP-Picodet)
– 表格识别(TableRec-RARE、TableMaster、SLANet)
– 关键信息抽取(SDMGR、LayoutLM、LayoutLMv2、LayoutXLM、VI-LayoutXLM)
1.6 数据工具
– 半自动标注工具PPOCRLabel
– 数据合成工具Style-Text
1.7 安装要求
1.7.1 操作系统要求
– Windows 7/8/10 专业版/企业版
– Ubuntu 18.04/20.04
– CentOS 7
– MacOS 10.x/11.x/12.x/13.x/14.x
注:操作系统要求是 64 位版本
1.7.2 处理器要求
– 处理器支持 MKL
– 处理器架构是x86_64(或称作x64、Intel 64、AMD64)架构,目前 PaddlePaddle 不支持arm64架构
1.7.3 Python和pip版本要求
– Python 的版本要求 3.8/3.9/3.10/3.11/3.12
– Python 具有 pip, 且 pip 的版本要求 20.2.2+
– Python 和 pip 要求是 64 位版本
2 最佳实践
2.1 软件简介
OS = Oracle Linux 9.x
IP Address = any
2.2 安装Python相关
2.2.1 安装Python
dnf install -y python3
然后,你可以以下命令确认python的版本是否符合要求,
python -V
可见如下显示,
Python 3.9.18
2.2.2 安装pip
dnf install -y python3-pip python3 -m pip install --upgrade pip
然后,你可以以下命令确认pip的版本是否符合要求,
pip -V
可见如下显示,
pip 24.3.1 from /usr/local/lib/python3.9/site-packages/pip (python 3.9)
2.3 部署PaddlePaddle
2.3.1 安装PaddlePaddle
pip install paddlepaddle
2.3.2 确认安装版本
pip list | grep paddlepaddle
可见如下显示,
paddlepaddle 2.6.2
然后,你可以使用如下命令测试安装的包,具体向导如下,
$ python Python 3.9.18 (main, Jan 24 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3.0.1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import paddle >>> print(paddle.__version__)
2.4 部署PaddleOCR
2.4.1 安装PaddleOCR
pip install paddleocr
2.4.2 创建运行用户并切换
useradd -d /data/python python su - python
2.4.3 测试安装
$ python Python 3.9.18 (main, Jan 24 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3.0.1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import paddleocr
如果遇到如下错误,
ImportError: libGL.so.1: cannot open shared object file: No such file or directory
你需要使用如下命令解决依关系,
dnf install -y mesa-libGL
2.5 测试PaddleOCR
2.5.1 部署测试环境
su - python wget https://paddleocr.bj.bcebos.com/dygraph_v2.1/ppocr_img.zip unzip ppocr_img.zip
2.5.2 确认测试文件路径
cd ppocr_img
2.5.3 测试中文图片识别
paddleocr --image_dir ./imgs/11.jpg --use_angle_cls true --use_gpu false
正常情况下你可以见到如下显示,
[2024/11/14 16:29:59] ppocr INFO: for usage help, please use `paddleocr --help` download https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar to /root/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer/ch_ppocr_mobile_v2.0_cls_infer.tar [2024/11/14 16:29:59] ppocr INFO: Path /root/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer/ch_ppocr_mobile_v2.0_cls_infer.tar already exists. Skipping... [2024/11/14 16:29:59] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=False, use_xpu=False, use_npu=False, use_mlu=False, ir_optim=True, use_tensorrt=False, min_subgraph_size=15, precision='fp32', gpu_mem=500, gpu_id=0, image_dir='./imgs/11.jpg', page_num=0, det_algorithm='DB', det_model_dir='/root/.paddleocr/whl/det/ch/ch_PP-OCRv4_det_infer', det_limit_side_len=960, det_limit_type='max', det_box_type='quad', det_db_thresh=0.3, det_db_box_thresh=0.6, det_db_unclip_ratio=1.5, max_batch_size=10, 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_pse_thresh=0, det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, scales=[8, 16, 32], alpha=1.0, beta=1.0, fourier_degree=5, rec_algorithm='SVTR_LCNet', rec_model_dir='/root/.paddleocr/whl/rec/ch/ch_PP-OCRv4_rec_infer', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='/usr/local/lib/python3.9/site-packages/paddleocr/ppocr/utils/ppocr_keys_v1.txt', use_space_char=True, vis_font_path='./doc/fonts/simfang.ttf', drop_score=0.5, e2e_algorithm='PGNet', e2e_model_dir=None, e2e_limit_side_len=768, e2e_limit_type='max', e2e_pgnet_score_thresh=0.5, e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_pgnet_valid_set='totaltext', e2e_pgnet_mode='fast', use_angle_cls=True, cls_model_dir='/root/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer', cls_image_shape='3, 48, 192', label_list=['0', '180'], cls_batch_num=6, cls_thresh=0.9, enable_mkldnn=False, cpu_threads=10, use_pdserving=False, warmup=False, sr_model_dir=None, sr_image_shape='3, 32, 128', sr_batch_num=1, draw_img_save_dir='./inference_results', save_crop_res=False, crop_res_save_dir='./output', use_mp=False, total_process_num=1, process_id=0, benchmark=False, save_log_path='./log_output/', show_log=True, use_onnx=False, return_word_box=False, output='./output', table_max_len=488, table_algorithm='TableAttn', table_model_dir=None, merge_no_span_structure=True, table_char_dict_path=None, formula_algorithm='LaTeXOCR', formula_model_dir=None, formula_char_dict_path=None, formula_batch_num=1, layout_model_dir=None, layout_dict_path=None, layout_score_threshold=0.5, layout_nms_threshold=0.5, kie_algorithm='LayoutXLM', ser_model_dir=None, re_model_dir=None, use_visual_backbone=True, ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ocr_order_method=None, mode='structure', image_orientation=False, layout=True, table=True, formula=False, ocr=True, recovery=False, recovery_to_markdown=False, use_pdf2docx_api=False, invert=False, binarize=False, alphacolor=(255, 255, 255), lang='ch', det=True, rec=True, type='ocr', savefile=False, ocr_version='PP-OCRv4', structure_version='PP-StructureV2') [2024/11/14 16:29:59] ppocr INFO: **********./imgs/11.jpg********** [2024/11/14 16:29:59] ppocr DEBUG: dt_boxes num : 16, elapsed : 0.17044854164123535 [2024/11/14 16:30:00] ppocr DEBUG: cls num : 16, elapsed : 0.05373430252075195 [2024/11/14 16:30:01] ppocr DEBUG: rec_res num : 16, elapsed : 1.083709478378296 [2024/11/14 16:30:01] ppocr INFO: [[[28.0, 37.0], [302.0, 39.0], [302.0, 72.0], [27.0, 70.0]], ('纯臻营养护发素', 0.9978380799293518)] [2024/11/14 16:30:01] ppocr INFO: [[[26.0, 83.0], [173.0, 83.0], [173.0, 104.0], [26.0, 104.0]], ('产品信息/参数', 0.9898301959037781)] [2024/11/14 16:30:01] ppocr INFO: [[[27.0, 112.0], [331.0, 112.0], [331.0, 135.0], [27.0, 135.0]], ('(45元/每公斤,100公斤起订)', 0.9659186005592346)] [2024/11/14 16:30:01] ppocr INFO: [[[25.0, 143.0], [281.0, 143.0], [281.0, 165.0], [25.0, 165.0]], ('每瓶22元,1000瓶起订)', 0.9928638339042664)] [2024/11/14 16:30:01] ppocr INFO: [[[26.0, 179.0], [300.0, 179.0], [300.0, 195.0], [26.0, 195.0]], ('【品牌】:代加工方式/OEMODM', 0.9843931794166565)] [2024/11/14 16:30:01] ppocr INFO: [[[26.0, 210.0], [234.0, 210.0], [234.0, 227.0], [26.0, 227.0]], ('【品名】:纯臻营养护发素', 0.996315062046051)] [2024/11/14 16:30:01] ppocr INFO: [[[25.0, 239.0], [241.0, 239.0], [241.0, 259.0], [25.0, 259.0]], ('【产品编号】:YM-X-3011', 0.9848006963729858)] [2024/11/14 16:30:01] ppocr INFO: [[[413.0, 232.0], [430.0, 232.0], [430.0, 306.0], [413.0, 306.0]], ('ODMOEM', 0.9908034205436707)] [2024/11/14 16:30:01] ppocr INFO: [[[24.0, 271.0], [180.0, 271.0], [180.0, 290.0], [24.0, 290.0]], ('【净含量】:220ml', 0.9892313480377197)] [2024/11/14 16:30:01] ppocr INFO: [[[26.0, 303.0], [251.0, 303.0], [251.0, 319.0], [26.0, 319.0]], ('【适用人群】:适合所有肤质', 0.9909219145774841)] [2024/11/14 16:30:01] ppocr INFO: [[[26.0, 335.0], [344.0, 335.0], [344.0, 352.0], [26.0, 352.0]], ('【主要成分】:鲸蜡硬脂醇、燕麦β-葡聚', 0.9828623533248901)] [2024/11/14 16:30:01] ppocr INFO: [[[26.0, 364.0], [281.0, 364.0], [281.0, 384.0], [26.0, 384.0]], ('糖、椰油酰胺丙基甜菜碱、泛醌', 0.9505157470703125)] [2024/11/14 16:30:01] ppocr INFO: [[[368.0, 368.0], [477.0, 368.0], [477.0, 389.0], [368.0, 389.0]], ('(成品包材)', 0.9920712113380432)] [2024/11/14 16:30:01] ppocr INFO: [[[26.0, 397.0], [360.0, 397.0], [360.0, 414.0], [26.0, 414.0]], ('【主要功能】:可紧致头发磷层,从而达到', 0.9904314279556274)] [2024/11/14 16:30:01] ppocr INFO: [[[28.0, 429.0], [370.0, 429.0], [370.0, 445.0], [28.0, 445.0]], ('即时持久改善头发光泽的效果,给干燥的头', 0.9874169230461121)] [2024/11/14 16:30:01] ppocr INFO: [[[27.0, 458.0], [137.0, 458.0], [137.0, 479.0], [27.0, 479.0]], ('发足够的滋养', 0.9987380504608154)]
2.5.4 测试英文图片识别
paddleocr --image_dir ./imgs_en/img_11.jpg --use_angle_cls true --use_gpu false
正常情况下你可以见到如下显示,
[2024/11/14 16:42:57] ppocr INFO: for usage help, please use `paddleocr --help` [2024/11/14 16:42:57] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=False, use_xpu=False, use_npu=False, use_mlu=False, ir_optim=True, use_tensorrt=False, min_subgraph_size=15, precision='fp32', gpu_mem=500, gpu_id=0, image_dir='./imgs_en/img_11.jpg', page_num=0, det_algorithm='DB', det_model_dir='/data/python/.paddleocr/whl/det/ch/ch_PP-OCRv4_det_infer', det_limit_side_len=960, det_limit_type='max', det_box_type='quad', det_db_thresh=0.3, det_db_box_thresh=0.6, det_db_unclip_ratio=1.5, max_batch_size=10, 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_pse_thresh=0, det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, scales=[8, 16, 32], alpha=1.0, beta=1.0, fourier_degree=5, rec_algorithm='SVTR_LCNet', rec_model_dir='/data/python/.paddleocr/whl/rec/ch/ch_PP-OCRv4_rec_infer', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='/usr/local/lib/python3.9/site-packages/paddleocr/ppocr/utils/ppocr_keys_v1.txt', use_space_char=True, vis_font_path='./doc/fonts/simfang.ttf', drop_score=0.5, e2e_algorithm='PGNet', e2e_model_dir=None, e2e_limit_side_len=768, e2e_limit_type='max', e2e_pgnet_score_thresh=0.5, e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_pgnet_valid_set='totaltext', e2e_pgnet_mode='fast', use_angle_cls=True, cls_model_dir='/data/python/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer', cls_image_shape='3, 48, 192', label_list=['0', '180'], cls_batch_num=6, cls_thresh=0.9, enable_mkldnn=False, cpu_threads=10, use_pdserving=False, warmup=False, sr_model_dir=None, sr_image_shape='3, 32, 128', sr_batch_num=1, draw_img_save_dir='./inference_results', save_crop_res=False, crop_res_save_dir='./output', use_mp=False, total_process_num=1, process_id=0, benchmark=False, save_log_path='./log_output/', show_log=True, use_onnx=False, return_word_box=False, output='./output', table_max_len=488, table_algorithm='TableAttn', table_model_dir=None, merge_no_span_structure=True, table_char_dict_path=None, formula_algorithm='LaTeXOCR', formula_model_dir=None, formula_char_dict_path=None, formula_batch_num=1, layout_model_dir=None, layout_dict_path=None, layout_score_threshold=0.5, layout_nms_threshold=0.5, kie_algorithm='LayoutXLM', ser_model_dir=None, re_model_dir=None, use_visual_backbone=True, ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ocr_order_method=None, mode='structure', image_orientation=False, layout=True, table=True, formula=False, ocr=True, recovery=False, recovery_to_markdown=False, use_pdf2docx_api=False, invert=False, binarize=False, alphacolor=(255, 255, 255), lang='ch', det=True, rec=True, type='ocr', savefile=False, ocr_version='PP-OCRv4', structure_version='PP-StructureV2') [2024/11/14 16:42:58] ppocr INFO: **********./imgs_en/img_11.jpg********** [2024/11/14 16:42:58] ppocr DEBUG: dt_boxes num : 3, elapsed : 0.27750158309936523 [2024/11/14 16:42:58] ppocr DEBUG: cls num : 3, elapsed : 0.021882295608520508 [2024/11/14 16:42:58] ppocr DEBUG: rec_res num : 3, elapsed : 0.13480257987976074 [2024/11/14 16:42:58] ppocr INFO: [[[402.0, 62.0], [491.0, 49.0], [494.0, 69.0], [405.0, 82.0]], ('BEWAREOF', 0.9963716268539429)] [2024/11/14 16:42:58] ppocr INFO: [[[390.0, 80.0], [503.0, 65.0], [506.0, 88.0], [393.0, 103.0]], ('MAINTENANCE', 0.9849557876586914)] [2024/11/14 16:42:58] ppocr INFO: [[[414.0, 97.0], [482.0, 89.0], [485.0, 109.0], [416.0, 117.0]], ('VEHICLES', 0.9927048683166504)]
2.5.5 测试日语图片识别
paddleocr --image_dir 001.jpeg --use_angle_cls true --use_gpu false --lang japan
以上图片需要自己准备,正常情况下你可以见到如下显示,
[2024/11/14 17:04:16] ppocr INFO: for usage help, please use `paddleocr --help` [2024/11/14 17:04:16] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=False, use_xpu=False, use_npu=False, use_mlu=False, ir_optim=True, use_tensorrt=False, min_subgraph_size=15, precision='fp32', gpu_mem=500, gpu_id=0, image_dir='001.jpeg', page_num=0, det_algorithm='DB', det_model_dir='/data/python/.paddleocr/whl/det/ml/Multilingual_PP-OCRv3_det_infer', det_limit_side_len=960, det_limit_type='max', det_box_type='quad', det_db_thresh=0.3, det_db_box_thresh=0.6, det_db_unclip_ratio=1.5, max_batch_size=10, 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_pse_thresh=0, det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, scales=[8, 16, 32], alpha=1.0, beta=1.0, fourier_degree=5, rec_algorithm='SVTR_LCNet', rec_model_dir='/data/python/.paddleocr/whl/rec/japan/japan_PP-OCRv4_rec_infer', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='/usr/local/lib/python3.9/site-packages/paddleocr/ppocr/utils/dict/japan_dict.txt', use_space_char=True, vis_font_path='./doc/fonts/simfang.ttf', drop_score=0.5, e2e_algorithm='PGNet', e2e_model_dir=None, e2e_limit_side_len=768, e2e_limit_type='max', e2e_pgnet_score_thresh=0.5, e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_pgnet_valid_set='totaltext', e2e_pgnet_mode='fast', use_angle_cls=True, cls_model_dir='/data/python/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer', cls_image_shape='3, 48, 192', label_list=['0', '180'], cls_batch_num=6, cls_thresh=0.9, enable_mkldnn=False, cpu_threads=10, use_pdserving=False, warmup=False, sr_model_dir=None, sr_image_shape='3, 32, 128', sr_batch_num=1, draw_img_save_dir='./inference_results', save_crop_res=False, crop_res_save_dir='./output', use_mp=False, total_process_num=1, process_id=0, benchmark=False, save_log_path='./log_output/', show_log=True, use_onnx=False, return_word_box=False, output='./output', table_max_len=488, table_algorithm='TableAttn', table_model_dir=None, merge_no_span_structure=True, table_char_dict_path=None, formula_algorithm='LaTeXOCR', formula_model_dir=None, formula_char_dict_path=None, formula_batch_num=1, layout_model_dir=None, layout_dict_path=None, layout_score_threshold=0.5, layout_nms_threshold=0.5, kie_algorithm='LayoutXLM', ser_model_dir=None, re_model_dir=None, use_visual_backbone=True, ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ocr_order_method=None, mode='structure', image_orientation=False, layout=True, table=True, formula=False, ocr=True, recovery=False, recovery_to_markdown=False, use_pdf2docx_api=False, invert=False, binarize=False, alphacolor=(255, 255, 255), lang='japan', det=True, rec=True, type='ocr', savefile=False, ocr_version='PP-OCRv4', structure_version='PP-StructureV2') [2024/11/14 17:04:16] ppocr INFO: **********001.jpeg********** [2024/11/14 17:04:16] ppocr DEBUG: dt_boxes num : 23, elapsed : 0.14974141120910645 [2024/11/14 17:04:17] ppocr DEBUG: cls num : 23, elapsed : 0.0632176399230957 [2024/11/14 17:04:17] ppocr DEBUG: rec_res num : 23, elapsed : 0.55869460105896 [2024/11/14 17:04:17] ppocr INFO: [[[120.0, 112.0], [171.0, 120.0], [167.0, 143.0], [117.0, 135.0]], ('モナェチ', 0.6373938918113708)] [2024/11/14 17:04:17] ppocr INFO: [[[323.0, 110.0], [381.0, 107.0], [382.0, 136.0], [324.0, 139.0]], ('ルト渡', 0.7630725502967834)] [2024/11/14 17:04:17] ppocr INFO: [[[193.0, 120.0], [286.0, 112.0], [289.0, 140.0], [196.0, 148.0]], ('ハチミツ', 0.9589446187019348)] [2024/11/14 17:04:17] ppocr INFO: [[[126.0, 135.0], [182.0, 131.0], [184.0, 156.0], [128.0, 161.0]], ('ふつくら', 0.8200452923774719)] [2024/11/14 17:04:17] ppocr INFO: [[[187.0, 147.0], [259.0, 143.0], [260.0, 168.0], [188.0, 171.0]], ('(保澤成分', 0.7587621808052063)] [2024/11/14 17:04:17] ppocr INFO: [[[263.0, 142.0], [296.0, 138.0], [300.0, 162.0], [266.0, 167.0]], ('配合', 0.999565601348877)] [2024/11/14 17:04:17] ppocr INFO: [[[315.0, 140.0], [355.0, 136.0], [357.0, 155.0], [317.0, 159.0]], ('ルック', 0.5976872444152832)] [2024/11/14 17:04:17] ppocr INFO: [[[123.0, 173.0], [237.0, 181.0], [234.0, 221.0], [120.0, 212.0]], ('しっとり', 0.783356249332428)] [2024/11/14 17:04:17] ppocr INFO: [[[228.0, 175.0], [356.0, 169.0], [358.0, 218.0], [230.0, 224.0]], ('柔肌に', 0.9578971266746521)] [2024/11/14 17:04:17] ppocr INFO: [[[155.0, 225.0], [237.0, 231.0], [235.0, 255.0], [153.0, 250.0]], ('ぬつて洗し', 0.8407496213912964)] [2024/11/14 17:04:17] ppocr INFO: [[[232.0, 230.0], [327.0, 223.0], [329.0, 251.0], [234.0, 258.0]], ('流すだけ!', 0.9961435198783875)] [2024/11/14 17:04:17] ppocr INFO: [[[166.0, 298.0], [330.0, 300.0], [330.0, 341.0], [166.0, 339.0]], ('HONEY', 0.9995816349983215)] [2024/11/14 17:04:17] ppocr INFO: [[[196.0, 343.0], [297.0, 343.0], [297.0, 356.0], [196.0, 356.0]], ('FORHOTORE', 0.69338458776474)] [2024/11/14 17:04:17] ppocr INFO: [[[195.0, 355.0], [245.0, 358.0], [245.0, 372.0], [194.0, 370.0]], ('FAOE', 0.6566588282585144)] [2024/11/14 17:04:17] ppocr INFO: [[[249.0, 357.0], [300.0, 353.0], [301.0, 370.0], [250.0, 373.0]], ('BACK', 0.8561694025993347)] [2024/11/14 17:04:17] ppocr INFO: [[[178.0, 375.0], [260.0, 380.0], [259.0, 400.0], [176.0, 394.0]], ('ヨ一グル卜液', 0.8757443428039551)] [2024/11/14 17:04:17] ppocr INFO: [[[249.0, 382.0], [316.0, 373.0], [318.0, 394.0], [252.0, 402.0]], ('配合ハツク', 0.8149470090866089)]
2.5.6 Python代码测试
python from paddleocr import PaddleOCR ocr = PaddleOCR(lang='en') img_path = './imgs_en/img_11.jpg' result = ocr.ocr(img_path, det=True, cls=True) for idx in range(len(result)): res = result[idx] for line in res: print(line)
正常情况下你可以见到如下显示,
Python 3.9.18 (main, Jan 24 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3.0.1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from paddleocr import PaddleOCR >>> ocr = PaddleOCR(lang='en') [2024/11/15 08:32:05] ppocr DEBUG: Namespace(help='==SUPPRESS==', use_gpu=False, use_xpu=False, use_npu=False, use_mlu=False, ir_optim=True, use_tensorrt=False, min_subgraph_size=15, precision='fp32', gpu_mem=500, gpu_id=0, image_dir=None, page_num=0, det_algorithm='DB', det_model_dir='/data/python/.paddleocr/whl/det/en/en_PP-OCRv3_det_infer', det_limit_side_len=960, det_limit_type='max', det_box_type='quad', det_db_thresh=0.3, det_db_box_thresh=0.6, det_db_unclip_ratio=1.5, max_batch_size=10, 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_pse_thresh=0, det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, scales=[8, 16, 32], alpha=1.0, beta=1.0, fourier_degree=5, rec_algorithm='SVTR_LCNet', rec_model_dir='/data/python/.paddleocr/whl/rec/en/en_PP-OCRv4_rec_infer', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_batch_num=6, max_text_length=25, rec_char_dict_path='/usr/local/lib/python3.9/site-packages/paddleocr/ppocr/utils/en_dict.txt', use_space_char=True, vis_font_path='./doc/fonts/simfang.ttf', drop_score=0.5, e2e_algorithm='PGNet', e2e_model_dir=None, e2e_limit_side_len=768, e2e_limit_type='max', e2e_pgnet_score_thresh=0.5, e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_pgnet_valid_set='totaltext', e2e_pgnet_mode='fast', use_angle_cls=False, cls_model_dir='/data/python/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer', cls_image_shape='3, 48, 192', label_list=['0', '180'], cls_batch_num=6, cls_thresh=0.9, enable_mkldnn=False, cpu_threads=10, use_pdserving=False, warmup=False, sr_model_dir=None, sr_image_shape='3, 32, 128', sr_batch_num=1, draw_img_save_dir='./inference_results', save_crop_res=False, crop_res_save_dir='./output', use_mp=False, total_process_num=1, process_id=0, benchmark=False, save_log_path='./log_output/', show_log=True, use_onnx=False, return_word_box=False, output='./output', table_max_len=488, table_algorithm='TableAttn', table_model_dir=None, merge_no_span_structure=True, table_char_dict_path=None, formula_algorithm='LaTeXOCR', formula_model_dir=None, formula_char_dict_path=None, formula_batch_num=1, layout_model_dir=None, layout_dict_path=None, layout_score_threshold=0.5, layout_nms_threshold=0.5, kie_algorithm='LayoutXLM', ser_model_dir=None, re_model_dir=None, use_visual_backbone=True, ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ocr_order_method=None, mode='structure', image_orientation=False, layout=True, table=True, formula=False, ocr=True, recovery=False, recovery_to_markdown=False, use_pdf2docx_api=False, invert=False, binarize=False, alphacolor=(255, 255, 255), lang='en', det=True, rec=True, type='ocr', savefile=False, ocr_version='PP-OCRv4', structure_version='PP-StructureV2') >>> img_path = './imgs_en/img_11.jpg' >>> result = ocr.ocr(img_path, det=True, cls=True) [2024/11/15 08:32:27] ppocr WARNING: Since the angle classifier is not initialized, it will not be used during the forward process [2024/11/15 08:32:28] ppocr DEBUG: dt_boxes num : 3, elapsed : 0.24822688102722168 [2024/11/15 08:32:28] ppocr DEBUG: rec_res num : 3, elapsed : 0.09131622314453125 >>> for idx in range(len(result)): ... res = result[idx] ... for line in res: ... print(line) ... [[[401.0, 62.0], [492.0, 49.0], [494.0, 68.0], [403.0, 80.0]], ('BEWARE OF', 0.9639703035354614)] [[[390.0, 81.0], [502.0, 67.0], [505.0, 85.0], [392.0, 100.0]], ('MAINTENANCE', 0.9958158731460571)] [[[413.0, 97.0], [484.0, 89.0], [486.0, 108.0], [415.0, 116.0]], ('VEHICLES', 0.9961135387420654)] >>>
参阅文档
==============
官方主页
—————-
https://www.paddlepaddle.org.cn/
https://paddlepaddle.github.io/PaddleOCR/main/index.html
官方GitHub
————–
https://github.com/PaddlePaddle/PaddleOCR
PaddlePaddle的安装
—————
https://www.paddlepaddle.org.cn/documentation/docs/zh/install/index_cn.html
https://www.paddlepaddle.org.cn/install/quick?docurl=undefined
PaddleOCR的安装
—————
https://paddlepaddle.github.io/PaddleOCR/main/ppocr/quick_start.html
https://paddlepaddle.github.io/PaddleOCR/latest/quick_start.html
https://pypi.org/project/paddleocr/
https://github.com/PaddlePaddle/PaddleOCR/blob/main/doc/doc_ch/installation.md
使用指南
—————
https://www.paddlepaddle.org.cn/documentation/docs/zh/2.6/practices/cv/image_ocr.html
https://www.paddlepaddle.org.cn/documentation/docs/zh/guides/index_cn.html
OCR学习电子书
—————
https://paddlepaddle.github.io/PaddleOCR/latest/ppocr/blog/ocr_book.html#_1
没有评论