📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.
Optim ocrweb
SWHLb92b388ce54d
diff --git a/ocrweb/README.md b/ocrweb/README.mdindex 45040ff..3178135 100755--- a/ocrweb/README.md+++ b/ocrweb/README.md@@ -20,15 +20,7 @@</div>### config.yaml全局参数说明-```text-Global:- text_score: 0.5- use_angle_cls: true # 是否使用文本框分类模型,默认为True- use_text_det: true # 是否使用文本检测模型,默认为True- print_verbose: true # 使用打印各个阶段的运行时长到终端,默认为True- min_height: 30 # 图像高度小于30将不经过文本检测模型- width_height_ratio: 8 # 图像宽高比大于该值,则不经过文本检测模型-```+- 详情参见:[README](../python/README.md#configyaml中常用参数介绍)### 以Web方式运行@@ -36,13 +28,12 @@ Global:```shellpip install -r requirements.txt -i https://pypi.douban.com/simple/```-2. 下载`resources`目录+2. 下载`models`目录- 下载链接:[百度网盘](https://pan.baidu.com/s/1PTcgXG2zEgQU6A_A3kGJ3Q?pwd=jhai) | [Google Drive](https://drive.google.com/drive/folders/1x_a9KpCo_1blxH1xFOfgKVkw1HYRVywY?usp=sharing)- 最终目录结构如下:```textocrweb├── README.md- ├── config.yaml├── main.py├── requirements.txt├── task.py@@ -51,8 +42,8 @@ Global:│ ├── ch_ppocr_v3_det│ ├── ch_ppocr_v2_cls│ ├── ch_ppocr_v3_rec- │ └── rapid_ocr_api.py- ├── resources+ │ ├── config.yaml+ │ ├── rapid_ocr_api.py│ └── models│ ├── ch_PP-OCRv3_det_infer.onnx│ ├── ch_ppocr_mobile_v2.0_cls_infer.onnxdiff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/config.yaml b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/config.yamlindex 89497ae..79e1a02 100644--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/config.yaml+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/config.yaml@@ -1,4 +1,4 @@-model_path: resources/models/ch_ppocr_mobile_v2.0_cls_infer.onnx+model_path: models/ch_ppocr_mobile_v2.0_cls_infer.onnxuse_cuda: false# Details of the params: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.htmldiff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.pyindex a15cd65..570a0b7 100644--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v2_cls/utils.py@@ -18,6 +18,7 @@ import yamlfrom onnxruntime import (get_available_providers, get_device,SessionOptions, InferenceSession,GraphOptimizationLevel)+root_dir = Path(__file__).resolve().parent.parentclass OrtInferSession(object):@@ -39,6 +40,7 @@ class OrtInferSession(object):EP_list = [(cuda_ep, config[cuda_ep])]EP_list.append((cpu_ep, cpu_provider_options))+ config['model_path'] = str(root_dir / config['model_path'])self._verify_model(config['model_path'])self.session = InferenceSession(config['model_path'],sess_options=sess_opt,@@ -87,4 +89,4 @@ class ClsPostProcess(object):return decode_outlabel = [(self.label_list[idx], 1.0) for idx in label]- return decode_out, label\ No newline at end of file+ return decode_out, labeldiff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/config.yaml b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/config.yamlindex bafce72..c6d4073 100644--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/config.yaml+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/config.yaml@@ -1,4 +1,4 @@-model_path: resources/models/ch_PP-OCRv3_det_infer.onnx+model_path: models/ch_PP-OCRv3_det_infer.onnxuse_cuda: false# Details of the params: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.htmldiff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.pyindex c2c9e17..0cdae63 100644--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_det/utils.py@@ -29,6 +29,7 @@ from shapely.geometry import Polygonfrom onnxruntime import (get_available_providers, get_device,SessionOptions, InferenceSession,GraphOptimizationLevel)+root_dir = Path(__file__).resolve().parent.parentclass OrtInferSession(object):@@ -50,6 +51,7 @@ class OrtInferSession(object):EP_list = [(cuda_ep, config[cuda_ep])]EP_list.append((cpu_ep, cpu_provider_options))+ config['model_path'] = str(root_dir / config['model_path'])self._verify_model(config['model_path'])self.session = InferenceSession(config['model_path'],sess_options=sess_opt,diff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/config.yaml b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/config.yamlindex 5df6390..1526f9b 100644--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/config.yaml+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/config.yaml@@ -1,4 +1,4 @@-model_path: resources/models/ch_PP-OCRv3_rec_infer.onnx+model_path: models/ch_PP-OCRv3_rec_infer.onnxuse_cuda: false# Details of the params: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.htmldiff --git a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.pyindex 1938404..954c4f8 100644--- a/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py+++ b/ocrweb/rapidocr_onnxruntime/ch_ppocr_v3_rec/utils.py@@ -9,6 +9,7 @@ import yamlfrom onnxruntime import (get_available_providers, get_device,SessionOptions, InferenceSession,GraphOptimizationLevel)+root_dir = Path(__file__).resolve().parent.parentclass OrtInferSession(object):@@ -30,6 +31,7 @@ class OrtInferSession(object):EP_list = [(cuda_ep, config[cuda_ep])]EP_list.append((cpu_ep, cpu_provider_options))+ config['model_path'] = str(root_dir / config['model_path'])self._verify_model(config['model_path'])self.session = InferenceSession(config['model_path'],sess_options=sess_opt,diff --git a/ocrweb/config.yaml b/ocrweb/rapidocr_onnxruntime/config.yamlsimilarity index 90%rename from ocrweb/config.yamlrename to ocrweb/rapidocr_onnxruntime/config.yamlindex 81de531..4b849b7 100644--- a/ocrweb/config.yaml+++ b/ocrweb/rapidocr_onnxruntime/config.yaml@@ -9,7 +9,7 @@ Global:Det:module_name: ch_ppocr_v3_detclass_name: TextDetector- model_path: resources/models/ch_PP-OCRv3_det_infer.onnx+ model_path: models/ch_PP-OCRv3_det_infer.onnxuse_cuda: false# Details of the params: https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html@@ -43,7 +43,7 @@ Det:Cls:module_name: ch_ppocr_v2_clsclass_name: TextClassifier- model_path: resources/models/ch_ppocr_mobile_v2.0_cls_infer.onnx+ model_path: models/ch_ppocr_mobile_v2.0_cls_infer.onnxuse_cuda: falseCUDAExecutionProvider:@@ -60,7 +60,7 @@ Cls:Rec:module_name: ch_ppocr_v3_recclass_name: TextRecognizer- model_path: resources/models/ch_PP-OCRv3_rec_infer.onnx+ model_path: models/ch_PP-OCRv3_rec_infer.onnxuse_cuda: falseCUDAExecutionProvider:diff --git a/ocrweb/resources/fonts/.gitkeep b/ocrweb/rapidocr_onnxruntime/models/.gitkeepsimilarity index 100%rename from ocrweb/resources/fonts/.gitkeeprename to ocrweb/rapidocr_onnxruntime/models/.gitkeepdiff --git a/ocrweb/rapidocr_onnxruntime/rapid_ocr_api.py b/ocrweb/rapidocr_onnxruntime/rapid_ocr_api.pyindex a3f4d4f..9ade4d5 100644--- a/ocrweb/rapidocr_onnxruntime/rapid_ocr_api.py+++ b/ocrweb/rapidocr_onnxruntime/rapid_ocr_api.py@@ -15,9 +15,12 @@ root_dir = Path(__file__).resolve().parentsys.path.append(str(root_dir))-class RapidOCR(object):+class RapidOCR():def __init__(self, config_path=str(root_dir / 'config.yaml')):super(RapidOCR).__init__()+ if not Path(config_path).exists():+ raise FileExistsError(f'{config_path} does not exist!')+config = self.read_yaml(config_path)global_config = config['Global']diff --git a/ocrweb/resources/models/.gitkeep b/ocrweb/resources/models/.gitkeepdeleted file mode 100644index e69de29..0000000diff --git a/ocrweb/task.py b/ocrweb/task.pyindex d428d2c..29f7eeb 100644--- a/ocrweb/task.py+++ b/ocrweb/task.py@@ -12,7 +12,7 @@ import numpy as npfrom rapidocr_onnxruntime import RapidOCR-text_sys = RapidOCR('config.yaml')+text_sys = RapidOCR()def detect_recognize(image_path, is_api=False):diff --git a/ocrweb/templates/index.html b/ocrweb/templates/index.htmlindex 1eed084..497bdfa 100644--- a/ocrweb/templates/index.html+++ b/ocrweb/templates/index.html@@ -3,12 +3,12 @@<head><meta charset="UTF-8"><title>RapidOCR Demo</title>- <link rel=stylesheet type="text/css" href="{{url_for('static', filename='css/main.css')}}">+ <link rel=stylesheet type="text/css" href="/static/css/main.css"><link rel="shortcut icon" href="/static/css/favicon.ico" type="image/x-icon"/></head><body><h1 align="center">- <b><i>Rapid🗲OCR Demo</i></b> + <b><i>RapidOCR Demo</i></b> <a href="https://github.com/RapidAI/RapidOCR" style="font-size: 14px;">欢迎Star</a> <a href="https://github.com/RapidAI/RapidOCR/tree/main/ocrweb#readme" style="font-size:14px">了解Demo</a></h1>