Skip to content

πŸ“„ Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

[ocrweb] Add return det boxes

SWHL8c0924b03e22
diff --git a/ocrweb/rapidocr_web/__init__.py b/ocrweb/rapidocr_web/__init__.py
index 0ecdd4f..d071b07 100644
--- a/ocrweb/rapidocr_web/__init__.py
+++ b/ocrweb/rapidocr_web/__init__.py
@@ -1,3 +1,3 @@
# -*- encoding: utf-8 -*-
# @Author: SWHL
-# @Contact: [email protected]
+# @Contact: [email protected]
\ No newline at end of file
diff --git a/ocrweb/rapidocr_web/ocrweb.py b/ocrweb/rapidocr_web/ocrweb.py
index e11c49e..1b0a2d2 100644
--- a/ocrweb/rapidocr_web/ocrweb.py
+++ b/ocrweb/rapidocr_web/ocrweb.py
@@ -6,7 +6,10 @@ from pathlib import Path
from wsgiref.simple_server import make_server
from flask import Flask, render_template, request
-from rapidocr_web.task import OCRWebUtils
+try:
+ from rapidocr_web.task import OCRWebUtils
+except:
+ from task import OCRWebUtils
root_dir = Path(__file__).resolve().parent
diff --git a/ocrweb/rapidocr_web/task.py b/ocrweb/rapidocr_web/task.py
index f37f591..20cc78e 100644
--- a/ocrweb/rapidocr_web/task.py
+++ b/ocrweb/rapidocr_web/task.py
@@ -18,7 +18,7 @@ class OCRWebUtils():
self.ocr = RapidOCR()
self.WebReturn = namedtuple(
'WebReturn',
- ['image', 'total_elapse', 'elapse_part', 'rec_res'])
+ ['image', 'total_elapse', 'elapse_part', 'rec_res', 'det_boxes'])
def __call__(self, img_content: str) -> namedtuple:
if img_content is None:
@@ -44,6 +44,7 @@ class OCRWebUtils():
total_elapse, elapse_part = 0, ''
img_str = self.img_to_base64(img)
rec_res = json.dumps([], indent=2, ensure_ascii=False)
+ boxes = ''
else:
boxes, txts, scores = list(zip(*ocr_res))
rec_res = list(zip(range(len(txts)), txts, scores))
@@ -58,7 +59,8 @@ class OCRWebUtils():
web_return = self.WebReturn(image=img_str,
total_elapse=f'{total_elapse:.4f}',
elapse_part=elapse_part,
- rec_res=rec_res)
+ rec_res=rec_res,
+ det_boxes=boxes)
return json.dumps(web_return._asdict())
@staticmethod