Skip to content

📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

Update ocrweb README

SWHL8ae0e21bc4bd
diff --git a/ocrweb/README.md b/ocrweb/README.md
index 29f856e..50f7fae 100755
--- a/ocrweb/README.md
+++ b/ocrweb/README.md
@@ -59,54 +59,64 @@
- API模式:
```python
# python 示例,本质就是发送一个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
+ class WebAPI():
+ def __init__(self, url: str) -> None:
+ self.url = url
+ self.header = {'Content-Type': 'application/json; charset=UTF-8'}
+ def __call__(self, img_path: str):
+ img_json = self.get_json_format(img_path)
+ response = requests.post(self.url,
+ data=img_json,
+ headers=self.header)
+ status_code = response.status_code
+ if status_code == 200:
+ return response.json()
+ raise ValueError(f'requests post error, status code is {status_code}')
+
+ @staticmethod
+ def get_json_format(img_path: str):
+ 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'}
+ if __name__ == '__main__':
+ web_url = 'http://localhost:9003/ocr'
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)
+
+ web_api = WebAPI(web_url)
+
+ res_rec = web_api(img_path)
+ print(res_rec)
```
4. API输出
- 示例结果:
- ```text
- [
- [[[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]
- ]
- ```
+ ```text
+ [
+ [[[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`类型,具体格式介绍如下:
- ```text
- [
- # 坐标为左上角 → 右上角 → 右下角 → 左下角
- [[[left, top], [right, top], [right, bottom], [left, bottom]], 识别文本, 置信度]
- ]
- ```
+ ```text
+ [
+ # 坐标为左上角 → 右上角 → 右下角 → 左下角
+ [[[left, top], [right, top], [right, bottom], [left, bottom]], 识别文本, 置信度]
+ ]
+ ```
- 如果没有检测到文字,则会输出空列表(`[]`)。
-
5. **!!说明:OCR的输出结果为最原始结果,大家可按需进一步扩展。**