Skip to content

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

Update api

SWHL7d53acda81fb
diff --git a/README.md b/README.md
index c188ca7..67681cd 100755
--- a/README.md
+++ b/README.md
@@ -32,9 +32,9 @@
- [简介](#简介)
- [文档导航](#文档导航)
- [近期更新(more)](#近期更新more)
+ - [🍜2023-05-22 api update:](#2023-05-22-api-update)
- [❤2023-05-20 ocrweb update:](#2023-05-20-ocrweb-update)
- [🌹2023-05-14 ocrweb v0.1.5 update:](#2023-05-14-ocrweb-v015-update)
- - [🏸2023-04-16 ocrweb v0.1.1 update:](#2023-04-16-ocrweb-v011-update)
- [生态框架](#生态框架)
- [在线demo](#在线demo)
- [TODO以及任务认领](#todo以及任务认领)
@@ -83,6 +83,7 @@
- [网页版OCR](https://github.com/RapidAI/RapidOCR/blob/main/ocrweb/README.md)
- [Nuitka打包rapdocr_web](https://github.com/RapidAI/RapidOCR/wiki/Nuitka%E6%89%93%E5%8C%85rapidocr_web%E6%93%8D%E4%BD%9C%E6%96%87%E6%A1%A3)
- [多语言网页版OCR](https://github.com/RapidAI/RapidOCR/blob/main/ocrweb_multi/README.md)
+- [API版](https://github.com/RapidAI/RapidOCR/tree/main/api)
- [版面结构化-RapidStructure](https://github.com/RapidAI/RapidStructure)
- [含文本的图像方向分类](https://github.com/RapidAI/RapidStructure/blob/main/docs/README_Orientation.md)
- [版面分析](https://github.com/RapidAI/RapidStructure/blob/main/docs/README_Layout.md)
@@ -100,6 +101,9 @@
## 近期更新([more](https://github.com/RapidAI/RapidOCR/wiki/%E6%9B%B4%E6%96%B0%E6%97%A5%E5%BF%97))
+#### 🍜2023-05-22 api update:
+- 将API从ocrweb中解耦出来,作为单独模块维护,详情参见[API](https://github.com/RapidAI/RapidOCR/tree/main/api)
+- `rapidocr_web>0.1.6`之后,将不支持`pip install rapidocr_web[api]`方式安装,可直接`pip install rapidocr_api`安装使用。
#### ❤2023-05-20 ocrweb update:
- 增加桌面版RapidOCRWeb,详情可参见[RapidOCRWeb桌面版使用教程](https://github.com/RapidAI/RapidOCR/wiki/%5BRapidOCRWeb%5D-%E6%A1%8C%E9%9D%A2%E7%89%88%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B)
- 对仓库文档做了整理,大部分文档放到了[Wiki](https://github.com/RapidAI/RapidOCR/wiki)
@@ -107,10 +111,6 @@
- 增加界面版返回坐标框的返回值([issue #85](https://github.com/RapidAI/RapidOCR/issues/85))
- API模式增加base64格式传入
- 详情参见:[link](https://github.com/RapidAI/RapidOCR/blob/main/ocrweb/README.md)
-#### 🏸2023-04-16 ocrweb v0.1.1 update:
-- API部署改为FastAPI库支持
-- 将API模式与Web解耦合,可通过`pip install rapidocr_web[api]`来选择性安装
-- 详情参见:[link](https://github.com/RapidAI/RapidOCR/blob/main/ocrweb/README.md)
## 生态框架
```mermaid
diff --git a/api/README.md b/api/README.md
index 86adfa7..3157bf1 100644
--- a/api/README.md
+++ b/api/README.md
@@ -7,12 +7,19 @@
<a href="https://pepy.tech/project/rapidocr_api"><img src="https://static.pepy.tech/personalized-badge/rapidocr_api?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads"></a>
</p>
+- ⚠️ 由于[pypi网站处于维护之中](https://status.python.org/),暂时不能上传whl包,后续如恢复,会再次上传。
- 采用FastAPI+uvicorn实现。
+- 该模块定位是一个快速搭建示例的demo,没有考虑多进程处理并发请求,如果有这需求的小伙伴,可以看看gunicorn等。
### 使用步骤
1. 安装`rapidocr_api`
```bash
$ pip install rapidocr_api
+
+ # 源码安装
+ $ python setup.py bdist_wheel v0.0.1
+ $ cd dist
+ $ pip install rapidocr_*.whl
```
2. 运行
- 用法:
@@ -29,36 +36,42 @@
```bash
$ rapidocr_api -ip 0.0.0.0 -p 9003
```
-3. 使用(本质就是发送一个POST请求,其他语言同理)
- - 以文件的方式发送请求
- ```python
- import requests
+3. 使用
+ - ⚠️:本质就是发送一个POST请求,其他语言同理
+ - curl调用
+ ```bash
+ $ curl -F [email protected] http://0.0.0.0:9003/ocr
+ ```
+ - python调用
+ - 以文件的方式发送请求
+ ```python
+ import requests
- url = 'http://localhost:9003/ocr'
- img_path = '../python/tests/test_files/ch_en_num.jpg'
+ url = 'http://localhost:9003/ocr'
+ img_path = '../python/tests/test_files/ch_en_num.jpg'
- with open(img_path, 'rb') as f:
- file_dict = {'image_file': (img_path, f, 'image/png')}
- response = requests.post(url, files=file_dict, timeout=60)
+ with open(img_path, 'rb') as f:
+ file_dict = {'image_file': (img_path, f, 'image/png')}
+ response = requests.post(url, files=file_dict, timeout=60)
- print(response.json())
- ```
- - 以`base64`方式发送post请求
- ```python
- import base64
- import requests
+ print(response.json())
+ ```
+ - 以`base64`方式发送post请求
+ ```python
+ import base64
+ import requests
- url = 'http://localhost:9003/ocr'
- img_path = '../python/tests/test_files/ch_en_num.jpg'
+ url = 'http://localhost:9003/ocr'
+ img_path = '../python/tests/test_files/ch_en_num.jpg'
- with open(img_path, 'rb') as fa:
- img_str = base64.b64encode(fa.read())
+ with open(img_path, 'rb') as fa:
+ img_str = base64.b64encode(fa.read())
- payload = {'image_data': img_str}
- resp = requests.post(url, data=payload)
+ payload = {'image_data': img_str}
+ resp = requests.post(url, data=payload)
- print(resp.json())
- ```
+ print(resp.json())
+ ```
4. API输出
- 示例结果:
<details>
@@ -67,71 +80,51 @@
```json
{
"0": {
- "rec_txt": "香港深圳抽血,",
+ "rec_txt": "8月26日!",
"dt_boxes": [
- [265, 18],
- [472, 231],
- [431, 271],
- [223, 59]
+ [333.0, 72.0],
+ [545.0, 40.0],
+ [552.0, 90.0],
+ [341.0, 122.0]
],
- "score": "0.8175641223788261"
+ "score": "0.7342076812471662"
},
"1": {
- "rec_txt": "专业查性别",
+ "rec_txt": "澳洲名校招生信息",
"dt_boxes": [
- [388, 15],
- [636, 257],
- [587, 307],
- [339, 65]
+ [266.0, 163.0],
+ [612.0, 116.0],
+ [619.0, 163.0],
+ [272.0, 210.0]
],
- "score": "0.8293875356515249"
+ "score": "0.8261737492349412"
},
"2": {
- "rec_txt": "专业鉴定B超单",
+ "rec_txt": "解读!!",
"dt_boxes": [
- [215, 84],
- [509, 413],
- [453, 463],
- [159, 134]
+ [341.0, 187.0],
+ [595.0, 179.0],
+ [598.0, 288.0],
+ [344.0, 296.0]
],
- "score": "0.8626169338822365"
+ "score": "0.6152311325073242"
},
"3": {
- "rec_txt": "b超仪器查性别",
- "dt_boxes": [
- [128, 135],
- [430, 478],
- [366, 534],
- [64, 192]
- ],
- "score": "0.8449362441897392"
- },
- "4": {
- "rec_txt": "加微信eee",
- "dt_boxes": [
- [58, 189],
- [268, 450],
- [209, 498],
- [0, 236]
- ],
- "score": "0.8176911813872201"
- },
- "5": {
- "rec_txt": "可邮寄",
+ "rec_txt": "Rules...",
"dt_boxes": [
- [493, 261],
- [617, 384],
- [577, 423],
- [454, 300]
+ [446.0, 321.0],
+ [560.0, 326.0],
+ [559.0, 352.0],
+ [445.0, 347.0]
],
- "score": "0.7494261413812637"
+ "score": "0.8704230123096042"
}
}
```
</details>
- 输出结果说明:
- - 如果图像中存在文字,则会输出json格式,具体格式介绍如下:
+ - 如果图像中存在文字,则会输出字典格式,具体介绍如下:
```python
{
"0": {
diff --git a/api/demo.py b/api/demo.py
index d65442d..0dddf98 100644
--- a/api/demo.py
+++ b/api/demo.py
@@ -11,4 +11,4 @@ with open(img_path, 'rb') as f:
file_dict = {'image_file': (img_path, f, 'image/png')}
response = requests.post(url, files=file_dict, timeout=60)
-print(response.json())
+print(response.text)
diff --git a/api/rapidocr_api/api.py b/api/rapidocr_api/api.py
index c2d7fa4..c599092 100644
--- a/api/rapidocr_api/api.py
+++ b/api/rapidocr_api/api.py
@@ -35,7 +35,7 @@ class OCRAPIUtils():
'dt_boxes': dt_box,
'score': score}
for i, (dt_box, rec, score) in enumerate(ocr_res)}
- return json.dumps(out_dict, indent=2, ensure_ascii=False)
+ return out_dict
app = FastAPI()
diff --git a/docs/README_en.md b/docs/README_en.md
index 3324992..1f5c346 100644
--- a/docs/README_en.md
+++ b/docs/README_en.md
@@ -28,10 +28,9 @@
- [Introduction](#introduction)
- [Navigation](#navigation)
- [Recently updates(more)](#recently-updatesmore)
+ - [🍜2023-05-22 api update:](#2023-05-22-api-update)
- [❤2023-05-20 ocrweb update:](#2023-05-20-ocrweb-update)
- [🌹 2023-05-14 ocrweb v0.1.5 update:](#-2023-05-14-ocrweb-v015-update)
- - [🏸2023-04-16 ocrweb v0.1.1 update:](#2023-04-16-ocrweb-v011-update)
- - [🎮2023-03-11 v1.2.2 update:](#2023-03-11-v122-update)
- [Overall Framework](#overall-framework)
- [Demo](#demo)
- [TODO and Task Claim](#todo-and-task-claim)
@@ -71,6 +70,7 @@
- [RapidOcrNcnnJvm](https://github.com/RapidAI/RapidOcrNcnnJvm)
- [.Net demo(C#)](https://github.com/RapidAI/RapidOCRCSharp)
- [Android demo](https://github.com/RapidAI/RapidOcrAndroidOnnx)
+- [API](https://github.com/RapidAI/RapidOCR/tree/main/api)
- Web demo:
- [Web OCR](https://github.com/RapidAI/RapidOCR/blob/main/ocrweb/README.md)
- [Nuitka package rapdocr_web](https://github.com/RapidAI/RapidOCR/wiki/Nuitka%E6%89%93%E5%8C%85rapidocr_web%E6%93%8D%E4%BD%9C%E6%96%87%E6%A1%A3)
@@ -97,18 +97,15 @@
- [FAQ](https://github.com/RapidAI/RapidOCR/blob/main/docs/FAQ.md)
## Recently updates([more](https://github.com/RapidAI/RapidOCR/wiki/Changelog))
+#### 🍜2023-05-22 api update:
+- Decouple the API from ocrweb and maintain it as a separate module. For details, see [API](https://github.com/RapidAI/RapidOCR/tree/main/api)
+- After `rapidocr_web>0.1.6`, `pip install rapidocr_web[api]` will not be supported for installation, you can directly install and use `pip install rapidocr_api`.
#### ❤2023-05-20 ocrweb update:
- Add desktop version of RapidOCRWeb, for details, please refer to [RapidOCRWeb desktop version tutorial](https://github.com/RapidAI/RapidOCR/wiki/%5BRapidOCRWeb%5D-%E6%A1%8C%E9%9D%A2%E7%89%88%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B)
#### 🌹 2023-05-14 ocrweb v0.1.5 update:
- Add the return value of the interface version's return coordinate box ([issue #85](https://github.com/RapidAI/RapidOCR/issues/85))
- API mode adds base64 format input
- For details, please refer to: [link](https://github.com/RapidAI/RapidOCR/blob/main/ocrweb/README.md)
-#### 🏸2023-04-16 ocrweb v0.1.1 update:
-- API deployment changed to FastAPI library support.
-- Decouple the API mode from the Web, which can be installed selectively through `pip install rapidocr_web[api]`.
-- See details for [link](https://github.com/RapidAI/RapidOCR/blob/main/ocrweb/README.md).
-#### 🎮2023-03-11 v1.2.2 update:
-- Fix the incoming parameter error of RapidOCR class in instantiation python
## Overall Framework
```mermaid
diff --git a/docs/doc_whl_rapidocr_api.md b/docs/doc_whl_rapidocr_api.md
index 08966db..9655c14 100644
--- a/docs/doc_whl_rapidocr_api.md
+++ b/docs/doc_whl_rapidocr_api.md
@@ -27,35 +27,40 @@
$ rapidocr_api -ip 0.0.0.0 -p 9003
```
3. Use
- - Send image data by file format.
- ```python
- import requests
+ - with curl
+ ```bash
+ $ curl -F [email protected] http://0.0.0.0:9003/ocr
+ ```
+ - with python
+ - Send image data by file format.
+ ```python
+ import requests
- url = 'http://localhost:9003/ocr'
- img_path = '../python/tests/test_files/ch_en_num.jpg'
+ url = 'http://localhost:9003/ocr'
+ img_path = '../python/tests/test_files/ch_en_num.jpg'
- with open(img_path, 'rb') as f:
- file_dict = {'image_file': (img_path, f, 'image/png')}
- response = requests.post(url, files=file_dict, timeout=60)
+ with open(img_path, 'rb') as f:
+ file_dict = {'image_file': (img_path, f, 'image/png')}
+ response = requests.post(url, files=file_dict, timeout=60)
- print(response.json())
- ```
- - Send image data by base64 format.
- ```python
- import base64
- import requests
+ print(response.json())
+ ```
+ - Send image data by base64 format.
+ ```python
+ import base64
+ import requests
- url = 'http://localhost:9003/ocr'
- img_path = '../python/tests/test_files/ch_en_num.jpg'
+ url = 'http://localhost:9003/ocr'
+ img_path = '../python/tests/test_files/ch_en_num.jpg'
- with open(img_path, 'rb') as fa:
- img_str = base64.b64encode(fa.read())
+ with open(img_path, 'rb') as fa:
+ img_str = base64.b64encode(fa.read())
- payload = {'image_data': img_str}
- resp = requests.post(url, data=payload)
+ payload = {'image_data': img_str}
+ resp = requests.post(url, data=payload)
- print(resp.json())
- ```
+ print(resp.json())
+ ```
4. Output
<details>
<summary>Click to expand</summary>
diff --git a/ocrweb/README.md b/ocrweb/README.md
index e810662..c90712c 100755
--- a/ocrweb/README.md
+++ b/ocrweb/README.md
@@ -15,7 +15,6 @@
### 简要说明
-- 该模块定位是一个快速搭建示例的demo,没有考虑多进程处理并发请求,如果有这需求的小伙伴,可以看看gunicorn等。
- 该模块依赖`rapidocr_onnxruntime`库。
- 如果想要离线部署,可以先手动下载[`rapidocr_onnxruntime`](https://pypi.org/project/rapidocr-onnxruntime/#files) whl包,再手动安装[`rapidocr_web`](https://pypi.org/project/rapidocr-web/#files) whl包来使用。
- 所用模型组合(最优组合)为: