Files
rapidocr/ocrweb
2023-01-16 23:05:28 +08:00
..
2022-12-12 22:25:53 +08:00
2023-01-16 23:05:28 +08:00
2022-10-13 09:37:26 +08:00
2022-10-13 09:37:26 +08:00
2022-12-14 17:18:38 +08:00
2023-01-04 10:10:32 +08:00
2023-01-04 10:10:32 +08:00

RapidOCR Web Demo

简要说明

  • 所用模型组合(最优组合)为:
    ch_PP-OCRv3_det + ch_ppocr_mobile_v2.0_cls + ch_PP-OCRv3_rec
    
  • 运行机器配置: 4核 AMD EPYC 7K62 48-Core Processor
  • 所有相关参数配置参见当前目录下的config.yaml,具体参数解释参见Link。
  • 网页上显示的推理时间具体解释如下:

以Web方式运行

  1. 安装rapidocr_onnxruntime

    $ pip install rapidocr_onnxruntime
    
  2. 安装ocrweb目录下的requirements.txt下相关包

    pip install -r requirements.txt
    
  3. 运行main.py

    $ python main.py
    
  4. 打开http://0.0.0.0:9003/即可, enjoy it!

以API方式运行

  1. 同以Web方式运行中步骤1

  2. 同以Web方式运行中步骤2

  3. 运行api.py

    $ python api.py
    
  4. 发送post请求,调用

    import ast
    import base64
    import json
    
    import requests
    
    
    def get_json_format(img_path):
        with open(img_path, 'rb') as f:
            img_byte = base64.b64encode(f.read())
        img_json = json.dumps({'file': img_byte.decode('ascii')})
        return img_json
    
    
    if __name__ == '__main__':
        url = 'http://localhost:9003/ocr'
        header = {'Content-Type': 'application/json; charset=UTF-8'}
    
        img_path = '../images/1.jpg'
        img_json = get_json_format(img_path)
    
        response = requests.post(url, data=img_json, headers=header)
        if response.status_code == 200:
            rec_res = ast.literal_eval(response.text)
            print(rec_res)
        else:
            print(response.status_code)
    
  5. 输出以下结果,即为正确。

     [
         [[[265.0, 18.0], [472.0, 231.0], [431.0, 271.0], [223.0, 59.0]], '香港深圳抽血', 0.8021483932222638],
         [[[388.0, 15.0], [636.0, 257.0], [587.0, 307.0], [339.0, 65.0]], '专业查性别', 0.7488822937011719],
         [[[215.0, 84.0], [509.0, 413.0], [453.0, 463.0], [159.0, 134.0]], '专业鉴定B超单', 0.8711239919066429],
         [[[128.0, 135.0], [430.0, 478.0], [366.0, 534.0], [64.0, 192.0]], 'b超仪器查性别', 0.8705329671502113],
         [[[58.0, 189.0], [268.0, 450.0], [209.0, 498.0], [0.0, 236.0]], '加微信eee', 0.8492027946880886],
         [[[493.0, 261.0], [617.0, 384.0], [577.0, 423.0], [454.0, 300.0]], '可邮寄', 0.7494295984506607]
     ]
    
    • 输出结果说明:
      • 如果图像中存在文字,则会输出list类型,具体格式介绍如下:
        [
            # 坐标为左上角 → 右上角 → 右下角 → 左下角
            [[[left, top], [right, top], [right, bottom], [left, bottom]], 识别文本, 置信度]
        ]
        
      • 如果没有检测到文字,则会输出空列表([])。
  6. !!说明:OCR的输出结果为最原始结果,大家可按需进一步扩展。