如何测试Docker paddleocr?

Python

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 部署容器环境

如何dnf部署Oracle Linux 9.x podman?

2.2 运行paddleocr

2.2.1 获取容器镜像

su - podman
podman pull paddlecloud/paddleocr:2.6-cpu-latest

2.2.2 测试容器运行

su - podman
podman run --name ppocr -v $PWD:/paddle --network=host -it paddlecloud/paddleocr:2.6-cpu-latest /bin/bash

另外,如果你需要删除该容器,

exit
podman container list -a
podman container rm d2cd86cdd45a

以上方法退出后可能容器会自动退出,临时的方法你可以使用如下命令运行,

su - podman
podman run -d --name ppocr -v $PWD:/paddle --network=host paddlecloud/paddleocr:2.6-cpu-latest tail -f /etc/debian_version

然后使用如下命令进入容器,

su - podman
podman exec -it ppocr /bin/bash

2.3 测试容器

2.5 测试PaddleOCR

2.5.1 部署测试环境

cd ~
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

正常情况下你可以见到如下显示,

grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
  warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('zope')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
[2024/11/15 02:24:44] ppocr DEBUG: Namespace(alpha=1.0, benchmark=False, beta=1.0, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir='/root/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer', cls_thresh=0.9, cpu_threads=10, crop_res_save_dir='./output', det=True, det_algorithm='DB', det_box_type='quad', det_db_box_thresh=0.6, det_db_score_mode='fast', det_db_thresh=0.3, det_db_unclip_ratio=1.5, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_east_score_thresh=0.8, det_limit_side_len=960, det_limit_type='max', det_model_dir='/root/.paddleocr/whl/det/ch/ch_PP-OCRv3_det_infer', det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, det_pse_thresh=0, det_sast_nms_thresh=0.2, det_sast_score_thresh=0.5, draw_img_save_dir='./inference_results', drop_score=0.5, e2e_algorithm='PGNet', e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_limit_side_len=768, e2e_limit_type='max', e2e_model_dir=None, e2e_pgnet_mode='fast', e2e_pgnet_score_thresh=0.5, e2e_pgnet_valid_set='totaltext', enable_mkldnn=False, fourier_degree=5, gpu_mem=500, help='==SUPPRESS==', image_dir='./imgs/11.jpg', image_orientation=False, ir_optim=True, kie_algorithm='LayoutXLM', label_list=['0', '180'], lang='ch', layout=True, layout_dict_path=None, layout_model_dir=None, layout_nms_threshold=0.5, layout_score_threshold=0.5, max_batch_size=10, max_text_length=25, merge_no_span_structure=True, min_subgraph_size=15, mode='structure', ocr=True, ocr_order_method=None, ocr_version='PP-OCRv3', output='./output', page_num=0, precision='fp32', process_id=0, re_model_dir=None, rec=True, rec_algorithm='SVTR_LCNet', rec_batch_num=6, rec_char_dict_path='/usr/local/lib/python3.7/dist-packages/paddleocr/ppocr/utils/ppocr_keys_v1.txt', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_model_dir='/root/.paddleocr/whl/rec/ch/ch_PP-OCRv3_rec_infer', recovery=False, save_crop_res=False, save_log_path='./log_output/', scales=[8, 16, 32], ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ser_model_dir=None, show_log=True, sr_batch_num=1, sr_image_shape='3, 32, 128', sr_model_dir=None, structure_version='PP-Structurev2', table=True, table_algorithm='TableAttn', table_char_dict_path=None, table_max_len=488, table_model_dir=None, total_process_num=1, type='ocr', use_angle_cls=True, use_dilation=False, use_gpu=False, use_mp=False, use_npu=False, use_onnx=False, use_pdf2docx_api=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, use_visual_backbone=True, use_xpu=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)
[2024/11/15 02:24:44] ppocr INFO: **********./imgs/11.jpg**********
[2024/11/15 02:24:44] ppocr DEBUG: dt_boxes num : 16, elapse : 0.18174266815185547
[2024/11/15 02:24:44] ppocr DEBUG: cls num  : 16, elapse : 0.09463024139404297
[2024/11/15 02:24:46] ppocr DEBUG: rec_res num  : 16, elapse : 1.9922289848327637
[2024/11/15 02:24:46] ppocr INFO: [[[28.0, 37.0], [302.0, 39.0], [302.0, 72.0], [27.0, 70.0]], ('纯臻营养护发素', 0.9658814072608948)]
[2024/11/15 02:24:46] ppocr INFO: [[[26.0, 81.0], [172.0, 83.0], [172.0, 104.0], [25.0, 101.0]], ('产品信息/参数', 0.9113279581069946)]
[2024/11/15 02:24:46] ppocr INFO: [[[28.0, 115.0], [330.0, 115.0], [330.0, 132.0], [28.0, 132.0]], ('(45元/每公斤,100公斤起订)', 0.8843424320220947)]
[2024/11/15 02:24:46] ppocr INFO: [[[27.0, 145.0], [282.0, 145.0], [282.0, 164.0], [27.0, 164.0]], ('每瓶22元,1000瓶起订)', 0.921172022819519)]
[2024/11/15 02:24:46] ppocr INFO: [[[26.0, 179.0], [299.0, 179.0], [299.0, 195.0], [26.0, 195.0]], ('【品牌】:代加工方式/OEMODM', 0.9661561250686646)]
[2024/11/15 02:24:46] ppocr INFO: [[[26.0, 210.0], [233.0, 210.0], [233.0, 227.0], [26.0, 227.0]], ('【品名】:纯臻营养护发素', 0.8831985592842102)]
[2024/11/15 02:24:46] ppocr INFO: [[[26.0, 241.0], [241.0, 241.0], [241.0, 258.0], [26.0, 258.0]], ('【产品编号】:YM-X-3011', 0.8718082308769226)]
[2024/11/15 02:24:46] ppocr INFO: [[[413.0, 236.0], [430.0, 236.0], [430.0, 303.0], [413.0, 303.0]], ('ODMOEM', 0.9539548754692078)]
[2024/11/15 02:24:46] ppocr INFO: [[[23.0, 271.0], [180.0, 269.0], [180.0, 289.0], [24.0, 290.0]], ('【净含量】:220ml', 0.9348663687705994)]
[2024/11/15 02:24:46] ppocr INFO: [[[26.0, 304.0], [252.0, 304.0], [252.0, 320.0], [26.0, 320.0]], ('适用人群):适合所有肤质', 0.886620044708252)]
[2024/11/15 02:24:46] ppocr INFO: [[[26.0, 335.0], [343.0, 335.0], [343.0, 352.0], [26.0, 352.0]], ('【主要成分】:鲸蜡硬脂醇、燕麦β-葡聚', 0.924584150314331)]
[2024/11/15 02:24:46] ppocr INFO: [[[27.0, 366.0], [281.0, 366.0], [281.0, 383.0], [27.0, 383.0]], ('糖、椰油酰胺丙基甜菜碱、泛醒', 0.9368206262588501)]
[2024/11/15 02:24:46] ppocr INFO: [[[369.0, 370.0], [477.0, 370.0], [477.0, 387.0], [369.0, 387.0]], ('(成品包材)', 0.8927560448646545)]
[2024/11/15 02:24:46] ppocr INFO: [[[26.0, 397.0], [361.0, 397.0], [361.0, 414.0], [26.0, 414.0]], ('【主要功能】:可紧致头发磷层,从而达到', 0.8677883148193359)]
[2024/11/15 02:24:46] ppocr INFO: [[[28.0, 429.0], [372.0, 429.0], [372.0, 445.0], [28.0, 445.0]], ('即时持久改善头发光泽的效果,给于燥的头', 0.8803373575210571)]
[2024/11/15 02:24:46] ppocr INFO: [[[27.0, 459.0], [136.0, 459.0], [136.0, 479.0], [27.0, 479.0]], ('发足够的滋养', 0.9091582298278809)]

如果遇到如下错误,

Traceback (most recent call last):
  File "/usr/bin/paddleocr", line 33, in 
    sys.exit(load_entry_point('paddleocr==2.6.1.0', 'console_scripts', 'paddleocr')())
  File "/usr/bin/paddleocr", line 22, in importlib_load_entry_point
    for entry_point in distribution(dist_name).entry_points
  File "/usr/local/lib/python3.7/dist-packages/importlib_metadata/__init__.py", line 975, in distribution
    return Distribution.from_name(distribution_name)
  File "/usr/local/lib/python3.7/dist-packages/importlib_metadata/__init__.py", line 566, in from_name
    raise PackageNotFoundError(name)
importlib_metadata.PackageNotFoundError: No package metadata was found for paddleocr

你需要执行如下命令修正,

pip3 install --upgrade pip
pip install paddleocr==2.6.1.0

2.5.4 测试英文图片识别

paddleocr --image_dir ./imgs_en/img_11.jpg --use_angle_cls true --use_gpu false

正常情况下你可以见到如下显示,

grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
  warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('zope')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
[2024/11/15 02:25:46] ppocr DEBUG: Namespace(alpha=1.0, benchmark=False, beta=1.0, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir='/root/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer', cls_thresh=0.9, cpu_threads=10, crop_res_save_dir='./output', det=True, det_algorithm='DB', det_box_type='quad', det_db_box_thresh=0.6, det_db_score_mode='fast', det_db_thresh=0.3, det_db_unclip_ratio=1.5, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_east_score_thresh=0.8, det_limit_side_len=960, det_limit_type='max', det_model_dir='/root/.paddleocr/whl/det/ch/ch_PP-OCRv3_det_infer', det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, det_pse_thresh=0, det_sast_nms_thresh=0.2, det_sast_score_thresh=0.5, draw_img_save_dir='./inference_results', drop_score=0.5, e2e_algorithm='PGNet', e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_limit_side_len=768, e2e_limit_type='max', e2e_model_dir=None, e2e_pgnet_mode='fast', e2e_pgnet_score_thresh=0.5, e2e_pgnet_valid_set='totaltext', enable_mkldnn=False, fourier_degree=5, gpu_mem=500, help='==SUPPRESS==', image_dir='./imgs_en/img_11.jpg', image_orientation=False, ir_optim=True, kie_algorithm='LayoutXLM', label_list=['0', '180'], lang='ch', layout=True, layout_dict_path=None, layout_model_dir=None, layout_nms_threshold=0.5, layout_score_threshold=0.5, max_batch_size=10, max_text_length=25, merge_no_span_structure=True, min_subgraph_size=15, mode='structure', ocr=True, ocr_order_method=None, ocr_version='PP-OCRv3', output='./output', page_num=0, precision='fp32', process_id=0, re_model_dir=None, rec=True, rec_algorithm='SVTR_LCNet', rec_batch_num=6, rec_char_dict_path='/usr/local/lib/python3.7/dist-packages/paddleocr/ppocr/utils/ppocr_keys_v1.txt', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_model_dir='/root/.paddleocr/whl/rec/ch/ch_PP-OCRv3_rec_infer', recovery=False, save_crop_res=False, save_log_path='./log_output/', scales=[8, 16, 32], ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ser_model_dir=None, show_log=True, sr_batch_num=1, sr_image_shape='3, 32, 128', sr_model_dir=None, structure_version='PP-Structurev2', table=True, table_algorithm='TableAttn', table_char_dict_path=None, table_max_len=488, table_model_dir=None, total_process_num=1, type='ocr', use_angle_cls=True, use_dilation=False, use_gpu=False, use_mp=False, use_npu=False, use_onnx=False, use_pdf2docx_api=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, use_visual_backbone=True, use_xpu=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)
[2024/11/15 02:25:47] ppocr INFO: **********./imgs_en/img_11.jpg**********
[2024/11/15 02:25:47] ppocr DEBUG: dt_boxes num : 3, elapse : 0.3188056945800781
[2024/11/15 02:25:47] ppocr DEBUG: cls num  : 3, elapse : 0.019107580184936523
[2024/11/15 02:25:47] ppocr DEBUG: rec_res num  : 3, elapse : 0.17826485633850098
[2024/11/15 02:25:47] ppocr INFO: [[[400.0, 62.0], [493.0, 48.0], [496.0, 69.0], [403.0, 82.0]], ('BEWAREOF', 0.9865339994430542)]
[2024/11/15 02:25:47] ppocr INFO: [[[390.0, 81.0], [502.0, 67.0], [505.0, 85.0], [392.0, 100.0]], ('MAINTENANCE', 0.8924415707588196)]
[2024/11/15 02:25:47] ppocr INFO: [[[413.0, 99.0], [484.0, 89.0], [486.0, 108.0], [415.0, 117.0]], ('VEHICLES', 0.991470456123352)]

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.7.13 (default, Apr 24 2022, 01:04:09) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from paddleocr import PaddleOCR
grep: warning: GREP_OPTIONS is deprecated; please use an alias or script
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
  warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
/usr/local/lib/python3.7/dist-packages/pkg_resources/__init__.py:2870: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('zope')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
>>> ocr = PaddleOCR(lang='en')
[2024/11/15 02:48:02] ppocr DEBUG: Namespace(alpha=1.0, benchmark=False, beta=1.0, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir='/root/.paddleocr/whl/cls/ch_ppocr_mobile_v2.0_cls_infer', cls_thresh=0.9, cpu_threads=10, crop_res_save_dir='./output', det=True, det_algorithm='DB', det_box_type='quad', det_db_box_thresh=0.6, det_db_score_mode='fast', det_db_thresh=0.3, det_db_unclip_ratio=1.5, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_east_score_thresh=0.8, det_limit_side_len=960, det_limit_type='max', det_model_dir='/root/.paddleocr/whl/det/en/en_PP-OCRv3_det_infer', det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, det_pse_thresh=0, det_sast_nms_thresh=0.2, det_sast_score_thresh=0.5, draw_img_save_dir='./inference_results', drop_score=0.5, e2e_algorithm='PGNet', e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_limit_side_len=768, e2e_limit_type='max', e2e_model_dir=None, e2e_pgnet_mode='fast', e2e_pgnet_score_thresh=0.5, e2e_pgnet_valid_set='totaltext', enable_mkldnn=False, fourier_degree=5, gpu_mem=500, help='==SUPPRESS==', image_dir=None, image_orientation=False, ir_optim=True, kie_algorithm='LayoutXLM', label_list=['0', '180'], lang='en', layout=True, layout_dict_path=None, layout_model_dir=None, layout_nms_threshold=0.5, layout_score_threshold=0.5, max_batch_size=10, max_text_length=25, merge_no_span_structure=True, min_subgraph_size=15, mode='structure', ocr=True, ocr_order_method=None, ocr_version='PP-OCRv3', output='./output', page_num=0, precision='fp32', process_id=0, re_model_dir=None, rec=True, rec_algorithm='SVTR_LCNet', rec_batch_num=6, rec_char_dict_path='/usr/local/lib/python3.7/dist-packages/paddleocr/ppocr/utils/en_dict.txt', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_model_dir='/root/.paddleocr/whl/rec/en/en_PP-OCRv3_rec_infer', recovery=False, save_crop_res=False, save_log_path='./log_output/', scales=[8, 16, 32], ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ser_model_dir=None, show_log=True, sr_batch_num=1, sr_image_shape='3, 32, 128', sr_model_dir=None, structure_version='PP-Structurev2', table=True, table_algorithm='TableAttn', table_char_dict_path=None, table_max_len=488, table_model_dir=None, total_process_num=1, type='ocr', use_angle_cls=False, use_dilation=False, use_gpu=False, use_mp=False, use_npu=False, use_onnx=False, use_pdf2docx_api=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, use_visual_backbone=True, use_xpu=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)
>>> img_path = './imgs_en/img_11.jpg'
>>> result = ocr.ocr(img_path, det=True, cls=True)
[2024/11/15 02:48:15] ppocr WARNING: Since the angle classifier is not initialized, the angle classifier will not be uesd during the forward process
[2024/11/15 02:48:16] ppocr DEBUG: dt_boxes num : 3, elapse : 0.2841012477874756
[2024/11/15 02:48:16] ppocr DEBUG: rec_res num  : 3, elapse : 0.16690397262573242
>>> 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.9630863666534424)]
[[[390.0, 81.0], [502.0, 67.0], [505.0, 85.0], [392.0, 100.0]], ('MAINTENANCE', 0.9932025671005249)]
[[[413.0, 97.0], [484.0, 89.0], [486.0, 108.0], [415.0, 116.0]], ('VEHICLES', 0.9965241551399231)]
>>> 

参阅文档
====================
https://paddlepaddle.github.io/PaddleOCR/latest/ppocr/installation.html#2-paddlepaddle-20
https://hub.docker.com/r/paddlecloud/paddleocr/tags

没有评论

发表回复

Python
如何部署Oracle Linux 9.x Python应用?

1 前言 一个问题,一篇文章,一出故事。 由于笔者今天接到部署Python的应用的工作任务,于是整理 …

Python
如何部署Windwos Python环境?

1 前言 一个问题,一篇文章,一出故事。 由于笔者今天接到部署Windows Python的工作任务 …

Python
如何Anaconda部署Oracle 9.x部署paddleocr?

1 基础知识 1.1 软件简介 PaddleOCR旨在打造一套丰富、领先、实用的OCR工具库 Pad …