PyPI

简介

  • 该包是将rapidocr_onnxruntime库做了API封装,采用FastAPI + uvicorn实现。
  • 定位是一个快速调用rapidocr_onnxruntime的API接口,没有考虑多进程处理并发请求,如果有这需求的小伙伴,可以看看gunicorn等。

安装

  pip install rapidocr_api
  

启动服务端

  • 用法:
      $ rapidocr_api -h
    usage: rapidocr_api [-h] [-ip IP] [-p PORT]
    
    optional arguments:
    -h, --help            show this help message and exit
    -ip IP, --ip IP       IP Address
    -p PORT, --port PORT  IP port
      
  • 启动:
      rapidocr_api -ip 0.0.0.0 -p 9003
      

调用

Curl调用

  curl -F image_file=@1.png http://0.0.0.0:9003/ocr
  

Python调用

API输出

  • 输出结果说明:
    • 如果图像中存在文字,则会输出字典格式,具体介绍如下:
        {
      "0": {
          "rec_txt": "香港深圳抽血,",  # 识别的文本
          "dt_boxes": [  # 依次为左上角 → 右上角 → 右下角 → 左下角
              [265, 18],
              [472, 231],
              [431, 271],
              [223, 59]
          ],
          "score": "0.8175641223788261"  # 置信度
          }
      }
        
    • 如果没有检测到文字,则会输出空字典({})。
  • 示例结果:
      {
        "0": {
            "rec_txt": "8月26日!",
            "dt_boxes": [
                [333.0, 72.0],
                [545.0, 40.0],
                [552.0, 90.0],
                [341.0, 122.0]
            ],
            "score": "0.7342076812471662"
        },
        "1": {
            "rec_txt": "澳洲名校招生信息",
            "dt_boxes": [
                [266.0, 163.0],
                [612.0, 116.0],
                [619.0, 163.0],
                [272.0, 210.0]
            ],
            "score": "0.8261737492349412"
        },
        "2": {
            "rec_txt": "解读!!",
            "dt_boxes": [
                [341.0, 187.0],
                [595.0, 179.0],
                [598.0, 288.0],
                [344.0, 296.0]
            ],
            "score": "0.6152311325073242"
        },
        "3": {
            "rec_txt": "Rules...",
            "dt_boxes": [
                [446.0, 321.0],
                [560.0, 326.0],
                [559.0, 352.0],
                [445.0, 347.0]
            ],
            "score": "0.8704230123096042"
        }
    }
      

Last updated 12 May 2024, 15:24 +0800 . history