Skip to content

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

Add dt_boxes of the api of ocrweb module api.

SWHL16e2eaf5438e
diff --git a/ocrweb/README.md b/ocrweb/README.md
index 07ce6c8..65d4711 100755
--- a/ocrweb/README.md
+++ b/ocrweb/README.md
@@ -85,10 +85,24 @@
5. 输出以下结果,即为正确。
```text
- [['0', '香港深圳抽血', '0.93583983'], ['1', '专业查性别', '0.89865875'], ['2', '专业鉴定B超单', '0.9955703'], ['3', 'b超仪器查性别', '0.99489486'], ['4', '加微信eee', '0.99073666'], ['5', '可邮寄', '0.99923944']]
+ [
+ [[[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`类型,如上。
+ - 如果图像中存在文字,则会输出`list`类型,具体格式介绍如下:
+ ```text
+ [
+ # 坐标为左上角→右上角→右下角→左下角
+ [[[left, top], [right, top], [right, bottom], [left, bottom]], 识别文本, 置信度]
+ ]
+ ```
- 如果没有检测到文字,则会输出空列表(`[]`)。
+ - 说明:OCR的输出结果为最原始结果,大家可按需进一步扩展。
### 相关问题
1. 各个阶段使用的模型以及配置参数有哪些?
diff --git a/ocrweb/api.py b/ocrweb/api.py
index e9a9009..bdbea45 100644
--- a/ocrweb/api.py
+++ b/ocrweb/api.py
@@ -3,6 +3,7 @@
# @Contact: [email protected]
import base64
from wsgiref.simple_server import make_server
+import json
import cv2
import numpy as np
diff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py
index 5d8fd22..4887188 100644
--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py
+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py
@@ -35,7 +35,7 @@ class TextRecognizer(object):
if 'character' in meta_dict.keys():
self.character_dict_path = meta_dict['character'].splitlines()
else:
- self.character_dict_path = config['keys_path']
+ self.character_dict_path = config.get('keys_path', None)
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
self.rec_batch_num = config['rec_batch_num']
diff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py
index 7fa9ac3..8f697c1 100644
--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py
+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py
@@ -72,7 +72,6 @@ class CTCLabelDecode(object):
self.character_str = character_dict_path
self.character_str.append(' ')
-
dict_character = self.add_special_char(self.character_str)
self.character = dict_character
diff --git a/ocrweb/task.py b/ocrweb/task.py
index f1abf2d..6cf3c9a 100644
--- a/ocrweb/task.py
+++ b/ocrweb/task.py
@@ -45,7 +45,12 @@ def detect_recognize(image_path, is_api=False):
elapse_part = ','.join([str(x) for x in elapse_part])
if is_api:
- return rec_res_data
+ fina_result = [[dt.tolist(), rec[0], rec[1]]
+ for dt, rec in zip(dt_boxes, rec_res)]
+ fina_reuslt_json = json.dumps(fina_result,
+ indent=2,
+ ensure_ascii=False)
+ return fina_reuslt_json
else:
return img_str, elapse, elapse_part, rec_res_data
diff --git a/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py b/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py
index 3204eae..b7a1b50 100644
--- a/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py
+++ b/python/rapidocr_onnxruntime/ch_ppocr_v3_rec/text_recognize.py
@@ -35,7 +35,7 @@ class TextRecognizer(object):
if 'character' in meta_dict.keys():
self.character_dict_path = meta_dict['character'].splitlines()
else:
- self.character_dict_path = config['keys_path']
+ self.character_dict_path = config.get('keys_path', None)
self.postprocess_op = CTCLabelDecode(self.character_dict_path)
self.rec_batch_num = config['rec_batch_num']