Skip to content

Latest commit

 

History

History
executable file
·
104 lines (89 loc) · 3.62 KB

README.md

File metadata and controls

executable file
·
104 lines (89 loc) · 3.62 KB

RapidOCR Web Demo

Web方式运行

  1. 安装requirements.txt下相关包

    pip install -r requirements.txt -i https://pypi.douban.com/simple/
  2. 下载resources目录

    • 下载链接:百度网盘 | Google Drive
    • 最终目录结构如下:
      ocrweb
      ├── README.md
      ├── config.yaml
      ├── main.py
      ├── requirements.txt
      ├── task.py
      ├── rapidocr_onnxruntime
      │   ├── __init__.py
      │   ├── ch_ppocr_v2_cls
      │   ├── ch_ppocr_v2_det
      │   ├── ch_ppocr_v2_rec
      │   └── rapid_ocr_api.py
      ├── resources
      │   ├── models
      │   │   ├── ch_PP-OCRv3_det_infer.onnx
      │   │   ├── ch_ppocr_mobile_v2.0_cls_infer.onnx
      │   │   └── ch_PP-OCRv3_rec_infer.onnx
      │   └── rec_dict
      │       └── ppocr_keys_v1.txt
      ├── static
      │   ├── css
      │   └── js
      └── templates
          └── index.html
      
  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. 输出以下结果,即为正确。

    [['0', '香港深圳抽血', '0.93583983'], ['1', '专业查性别', '0.89865875'], ['2', '专业鉴定B超单', '0.9955703'], ['3', 'b超仪器查性别', '0.99489486'], ['4', '加微信eee', '0.99073666'], ['5', '可邮寄', '0.99923944']]
    
    • 如果图像中存在文字,则会输出list类型,如上。
    • 如果没有检测到文字,则会输出空列表([])。

相关问题

  1. 各个阶段使用的模型以及配置参数有哪些?
    • 使用模型搭配(最优组合)为:ch_PP-OCRv3_det + ch_ppocr_mobile_v2.0_cls + ch_PP-OCRv3_rec
    • 所有相关参数配置参见当前目录下的config.yaml文件
    • 其中给出了使用模型,以及具体参数,参数具体介绍参见:Link
  2. 网页上显示的推理时间可以具体解释一下吗?