
from paddleocr import PaddleOCR import time # 初始化 PaddleOCR 实例 ocr PaddleOCR( # 1. 文档级别的预处理 # 文档方向分类: # 作用作用判断图片是否需要旋转0° / 90° / 180° / 270° # 什么时候开 # 扫描件 / 拍照文档建议开启 # 已保证方向正确可关闭 use_doc_orientation_classifyNone, doc_orientation_classify_model_nameNone, doc_orientation_classify_model_dirNone, # 文档去畸变拉平 # 作用把弯曲页面书页、拍照拉平 # 什么时候开 # 拍书 / 手机拍文档 → 开 # PDF / 截图 → 关 doc_unwarping_model_nameNone, doc_unwarping_model_dirNone, use_doc_unwarpingNone, # 2. 文本检测 # 检测文字框位置核心步骤 text_detection_model_nameNone, text_detection_model_dirNone, # 检测文本相关参数 # 控制输入图片缩放 text_det_limit_side_lenNone, # 最大边长默认 960 / 1024 text_det_limit_typeNone, # max最长边限制, 或者 min最短边限制 # 检测阈值(非常重要) text_det_threshNone, # 像素级阈值, 像素是否是文字 text_det_box_threshNone, # 框置信度, 框的保留阈值 text_det_unclip_ratioNone, # 框扩展比例, 框扩大倍数 # 3. 行方向分类 # 作用: 判断每一行是不是倒着的 # 使用场景 # 多角度文本比如发票、票据 textline_orientation_model_nameNone, textline_orientation_model_dirNone, textline_orientation_batch_sizeNone, use_textline_orientationNone, # 4. 文本识别Text Recognition # 作用: 把文字框转成文本 text_recognition_model_nameNone, text_recognition_model_dirNone, text_recognition_batch_sizeNone, text_rec_score_threshNone, # 低于这个置信度的结果会被过滤 # 5. 语言和模型版本 langen, # ch 中文英文, en 英文 ocr_versionNone, # PP-OCRv4 或者 PP-OCRv5 # 6. 输出控制 return_word_boxNone, # 是否返回“单词级框” # 7. 输入尺寸相关 text_det_input_shapeNone, # 检测位置的输入尺寸 text_rec_input_shapeNone, # 文本识别的输入尺寸 # det_model_dir/media/fx/Elements SE/广西模型/official_models/PP-OCRv5_server_det, # rec_model_dir/media/fx/Elements SE/广西模型/official_models/PP-OCRv5_server_rec, ) # 对示例图像执行 OCR 推理 result ocr.predict(./resource/images/7.jpg) # 可视化结果并保存 json 结果 for res in result: res.print() res.save_to_img(output) # res.save_to_json(output)