PaddleOCR百度飞桨OCR - PP-OCRv5 API解释

介绍

官方api

https://paddlepaddle.github.io/PaddleOCR/latest/version3.x/pipeline_usage/OCR.html#22-python

如下图:

例子

from paddleocr import PaddleOCR
import time


# 初始化 PaddleOCR 实例
ocr = PaddleOCR(
    use_doc_orientation_classify = True, # 文档方向分类,默认值为True。适用古籍竖排文字
    use_doc_unwarping = True, # 是否使用文档扭曲矫正模块,默认值为True
    use_textline_orientation = True, # 是否使用文本行方向分类模块
    # det_model_dir='PP-OCRv5_mobile_det',  # 检测模型路径
    # rec_model_dir='PP-OCRv5_mobile_rec',  # 识别模型路径
    text_detection_model_name="PP-OCRv5_mobile_det", # 指定mobile轻量模型,使用CPU执行快,但准确率低
    text_recognition_model_name="PP-OCRv5_mobile_rec", # 指定mobile轻量模型,使用CPU执行快,但准确率低
)
print("加载模型完毕!")
# 对示例图像执行 OCR 推理 
start_time = time.time()
result = ocr.predict(input="2.png")
# 记录结束时间并计算耗时
end_time = time.time()
elapsed_time = end_time - start_time
print(f"代码执行耗时: {elapsed_time:.4f} 秒")

# 可视化结果并保存 json 结果
for res in result:
    # res.print()
    res.save_to_json(save_path="./output/5_mobile_res.json")
    # res.save_to_img(save_path="./output/2.png")

原文出处:/show_1GW1S53RssR1.html