-
安装
requirements.txt
下相关包pip install -r requirements.txt -i https://pypi.douban.com/simple/
-
下载
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
-
运行
main.py
python main.py
-
打开
http://0.0.0.0:9003/
即可, enjoy it!
-
同Web方式运行中步骤1
-
同Web方式运行中步骤2
-
运行
api.py
python api.py
-
发送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)
-
输出以下结果,即为正确。
[['0', '香港深圳抽血', '0.93583983'], ['1', '专业查性别', '0.89865875'], ['2', '专业鉴定B超单', '0.9955703'], ['3', 'b超仪器查性别', '0.99489486'], ['4', '加微信eee', '0.99073666'], ['5', '可邮寄', '0.99923944']]
- 如果图像中存在文字,则会输出
list
类型,如上。 - 如果没有检测到文字,则会输出空列表(
[]
)。
- 如果图像中存在文字,则会输出
- 各个阶段使用的模型以及配置参数有哪些?
- 使用模型搭配(最优组合)为:
ch_PP-OCRv3_det + ch_ppocr_mobile_v2.0_cls + ch_PP-OCRv3_rec
- 所有相关参数配置参见当前目录下的
config.yaml
文件 - 其中给出了使用模型,以及具体参数,参数具体介绍参见:Link
- 使用模型搭配(最优组合)为:
- 网页上显示的推理时间可以具体解释一下吗?