Skip to content

Commit 2e6749b

Browse files
committed
Fixing cyclic dependencies
1 parent 5136195 commit 2e6749b

2 files changed

Lines changed: 281 additions & 5 deletions

File tree

python/rapidocr/parameters.md

Lines changed: 280 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,280 @@
1+
---
2+
comments: true
3+
hide:
4+
- toc
5+
---
6+
7+
### `config.yaml`的生成
8+
9+
```bash linenums="1"
10+
rapidocr config
11+
```
12+
13+
### `default_rapidocr.yaml`常用参数介绍
14+
15+
#### Global
16+
17+
该部分为全局配置。
18+
19+
```yaml linenums="1"
20+
Global:
21+
text_score: 0.5
22+
23+
use_det: true
24+
use_cls: true
25+
use_rec: true
26+
27+
min_height: 30
28+
width_height_ratio: 8
29+
max_side_len: 2000
30+
min_side_len: 30
31+
32+
return_word_box: false
33+
return_single_char_box: false
34+
35+
font_path: null
36+
log_level: "info" # debug / info / warning / error / critical
37+
```
38+
39+
`text_score (float)`: 文本识别结果置信度,值越大,把握越大。取值范围:`[0, 1]`, 默认值是0.5。
40+
41+
`use_det (bool)`: 是否使用文本检测。默认为`True`。
42+
43+
`use_cls (bool)`: 是否使用文本行方向分类。默认为`True`。
44+
45+
`use_rec (bool)`: 是否使用文本行识别。默认为`True`。
46+
47+
`min_height (int)` : 图像最小高度(单位是像素),低于这个值,会跳过文本检测阶段,直接进行后续识别。默认值为30。`min_height`是用来过滤只有一行文本的图像(如下图),这类图像不会进入文本检测模块,直接进入后续过程。
48+
49+
![](https://github.com/RapidAI/RapidOCR/releases/download/v1.1.0/single_line_text.jpg)
50+
51+
`width_height_ratio (float)`: 如果输入图像的宽高比大于`width_height_ratio`,则会跳过文本检测,直接进行后续识别,取值为-1时:不用这个参数. 默认值为8。
52+
53+
`max_side_len (int)`: 如果输入图像的最大边大于`max_side_len`,则会按宽高比,将最大边缩放到`max_side_len`。默认为2000px。
54+
55+
`min_side_len (int)`: 如果输入图像的最小边小于`min_side_len`,则会按宽高比,将最小边缩放到`min_side_len`。默认为30px。
56+
57+
`return_word_box (bool)`: 是否返回文字的单字坐标。默认为`False`。
58+
59+
> 在`rapidocr>=2.1.0`中,纯中文、中英文混合返回单字坐标,纯英文返回单词坐标。
60+
61+
> 在`rapidocr<=2.0.7`中,纯中文、中英文混合和纯英文均返回单字坐标。
62+
63+
> 在`rapidocr_onnxruntime>=1.4.1`中,汉字返回单字坐标,英语返回单字母坐标。
64+
65+
> 在`rapidocr_onnxruntime==1.4.0`中,汉字会返回单字坐标,英语返回单词坐标。
66+
67+
`return_single_char_box (bool)`: 文本内容只有英文和数字情况下,是否返回单字坐标。默认为`False`。
68+
69+
> 在`rapidocr>=3.1.0`中添加该参数,该参数只有在`return_word_box=True`时,才能生效。
70+
71+
```python
72+
result = engine(img_url, return_word_box=True, return_single_char_box=True)
73+
```
74+
75+
`font_path (str)`: 字体文件路径。如不提供,程序会自动下载预置的字体文件模型到本地。默认为`null`。
76+
77+
`log_level (str)`: 日志级别设置。可选择的有`debug / info / warning / error / critical`,默认为`info`,会打印加载模型等日志。如果设置`critical`,则不会打印任何日志。
78+
79+
> 在`rapidocr>=3.4.0`中,才添加此参数。
80+
81+
#### EngineConfig
82+
83+
该部分为相关推理引擎的配置文件,大家可按需配置。该部分后面可能会增删部分关键字,如果有需求,可以在文档下面评论区指出。
84+
85+
```yaml linenums="1"
86+
EngineConfig:
87+
onnxruntime:
88+
intra_op_num_threads: -1
89+
inter_op_num_threads: -1
90+
enable_cpu_mem_arena: false
91+
92+
cpu_ep_cfg:
93+
arena_extend_strategy: "kSameAsRequested"
94+
95+
use_cuda: false
96+
cuda_ep_cfg:
97+
device_id: 0
98+
arena_extend_strategy: "kNextPowerOfTwo"
99+
cudnn_conv_algo_search: "EXHAUSTIVE"
100+
do_copy_in_default_stream: true
101+
102+
use_dml: false
103+
dm_ep_cfg: null
104+
105+
use_cann: false
106+
cann_ep_cfg:
107+
device_id: 0
108+
arena_extend_strategy: "kNextPowerOfTwo"
109+
npu_mem_limit: 21474836480 # 20 * 1024 * 1024 * 1024
110+
op_select_impl_mode: "high_performance"
111+
optypelist_for_implmode: "Gelu"
112+
enable_cann_graph: true
113+
114+
openvino:
115+
inference_num_threads: -1
116+
117+
paddle:
118+
cpu_math_library_num_threads: -1
119+
use_npu: false # rapidocr>=3.3.0
120+
npu_id: 0 # rapidocr>=3.3.0
121+
use_cuda: false
122+
gpu_id: 0
123+
gpu_mem: 500
124+
125+
torch:
126+
use_cuda: false
127+
gpu_id: 0
128+
use_npu: false # rapidocr>3.4.1
129+
npu_id: 0 # rapidocr>3.4.1
130+
```
131+
132+
该部分的详细使用,请参见:[如何使用不同推理引擎?](./how_to_use_infer_engine.md)
133+
134+
各个推理引擎的API:
135+
136+
- ONNXRuntime Python API 参见:[Python API](https://onnxruntime.ai/docs/api/python/api_summary.html)
137+
- OpenVINO Python API 参见:[OpenVINO Python API](https://docs.openvino.ai/2025/api/ie_python_api/api.html)
138+
- PaddlePaddle API 参见:[API 文档](https://www.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html)
139+
- PyTorch API 参见:[PyTorch documentation](https://pytorch.org/docs/stable/index.html)
140+
141+
以下三部分前4个参数基本类似,对应关系如下表,具体请参见[模型列表](../../model_list.md)文档:
142+
143+
| YAML 参数 | 对应枚举类 | 可用枚举值(示例) |导入方式 | 备注 |
144+
|-----------------|------------------|------------------|-------------------|-------------------------------------|
145+
| `engine_type` | `EngineType` | `ONNXRUNTIME`(onnxruntime)<br>`OPENVINO`(openvino)<br>`PADDLE`(paddle)<br>`TORCH`(torch) | `from rapidocr import EngineType`|推理引擎类型 |
146+
| `lang_type` | `LangDet`<br> `LangCls`<br> `LangRec` | **检测(Det)**:`CH`/`EN`/`MULTI`<br>**分类(Cls)**:`CH`<br>**识别(Rec)**:`CH`/`CH_DOC`/`EN`/`ARABIC`/... |`from rapidocr import LangDet`<br/> `from rapidocr import LangCls` <br/>`from rapidocr import LangRec`| 根据OCR处理阶段选择不同枚举值 |
147+
| `model_type` | `ModelType` | `MOBILE`(mobile)<br>`SERVER`(server) |`from rapidocr import ModelType`| 模型大小与性能级别 |
148+
| `ocr_version` | `OCRVersion` | `PPOCRV4`(PP-OCRv4)<br>`PPOCRV5`(PP-OCRv5) |`from rapidocr import OCRVersion`| 模型版本 |
149+
150+
#### Det
151+
152+
```yaml linenums="1"
153+
Det:
154+
engine_type: "onnxruntime"
155+
lang_type: "ch"
156+
model_type: "mobile"
157+
ocr_version: "PP-OCRv4"
158+
159+
task_type: "det"
160+
161+
model_path: null
162+
model_dir: null
163+
164+
limit_side_len: 736
165+
limit_type: min
166+
std: [ 0.5, 0.5, 0.5 ]
167+
mean: [ 0.5, 0.5, 0.5 ]
168+
169+
thresh: 0.3
170+
box_thresh: 0.5
171+
max_candidates: 1000
172+
unclip_ratio: 1.6
173+
use_dilation: true
174+
score_mode: fast
175+
```
176+
177+
`engine_type (str)`: 选定推理引擎。支持`onnxruntime`、`openvino`、`paddle`和`torch`四个值。默认为`onnxruntime`。
178+
179+
`lang_type (str)`: 支持检测的语种类型。这里指的是`LangDet`,具体支持`ch`、`en`和`multi`3个值。`ch`可以识别中文和中英文混合文本检测。`en`支持英文文字检测。`multi`支持多语言文本检测。默认为`ch`。
180+
181+
`model_type (str)`: 模型量级选择,支持`mobile`(轻量型)和`server`(服务型)。默认为`mobile`。
182+
183+
`ocr_version (str)`: ocr版本的选择,支持`PP-OCRv4`和`PP-OCRv5`,默认为`PP-OCRv4`。
184+
185+
`model_path (str)`: 文本检测模型路径,仅限于基于PaddleOCR训练所得DBNet文本检测模型。默认值为`null`。
186+
187+
`model_dir (str)`: 模型存放路径或目录。如果是PaddlePaddle,该参数则对应模型存在目录。其余推理引擎请使用`model_path`参数。
188+
189+
`limit_side_len (float)`: 限制图像边的长度的像素值。默认值为736。
190+
191+
`limit_type (str)`: 限制图像的最小边长度还是最大边为`limit_side_len`。 示例解释:当`limit_type=min`和`limit_side_len=736`时,图像最小边小于736时,会将图像最小边拉伸到736,另一边则按图像原始比例等比缩放。 取值范围为:`[min, max]`,默认值为`min`。
192+
193+
`thresh (float)`: 图像中文字部分和背景部分分割阈值。值越大,文字部分会越小。取值范围:`[0, 1]`,默认值为0.3。
194+
195+
`box_thresh (float)`: 文本检测所得框是否保留的阈值,值越大,召回率越低。取值范围:`[0, 1]`,默认值为0.5。
196+
197+
`max_candidates (int)`: 最大候选框数目。默认是1000。
198+
199+
`unclip_ratio (float)`: 控制文本检测框的大小,值越大,检测框整体越大。取值范围:`[1.6, 2.0]`,默认值为1.6。
200+
201+
`use_dilation (bool)`: 是否使用膨胀。默认为`true`。该参数用于将检测到的文本区域做形态学的膨胀处理。
202+
203+
`score_mode (str)`: 计算文本框得分的方式。取值范围为:`[slow, fast]`,默认值为`fast`。
204+
205+
#### Cls
206+
207+
```yaml linenums="1"
208+
Cls:
209+
engine_type: "onnxruntime"
210+
lang_type: "ch"
211+
model_type: "mobile"
212+
ocr_version: "PP-OCRv4"
213+
214+
task_type: "cls"
215+
216+
model_path: null
217+
model_dir: null
218+
219+
cls_image_shape: [3, 48, 192]
220+
cls_batch_num: 6
221+
cls_thresh: 0.9
222+
label_list: ["0", "180"]
223+
```
224+
225+
`engine_type (str)`: 同Det部分介绍。
226+
227+
`lang_type (str)`: 支持检测的语种类型。这里指的是`LangCls`,目前只有一种选项:`ch`。默认为`ch`。
228+
229+
`model_type (str)`: 同Det部分介绍。
230+
231+
`ocr_version (str)`: 同Det部分介绍。
232+
233+
`model_path (str)`: 文本行方向分类模型路径,仅限于PaddleOCR训练所得二分类分类模型。默认值为`None`。
234+
235+
`model_dir (str)`: 占位参数,暂时无效。
236+
237+
`cls_image_shape (List[int])`: 输入方向分类模型的图像Shape(CHW)。默认值为`[3, 48, 192]`。
238+
239+
`cls_batch_num (int)`: 批次推理的batch大小,一般采用默认值即可,太大并没有明显提速,效果还可能会差。默认值为6。
240+
241+
`cls_thresh (float)`: 方向分类结果的置信度。取值范围:`[0, 1]`,默认值为0.9。
242+
243+
`label_list (List[str])`: 方向分类的标签,0°或者180°,**该参数不能动** 。默认值为`["0", "180"]`。
244+
245+
#### Rec
246+
247+
```yaml linenums="1"
248+
Rec:
249+
engine_type: "onnxruntime"
250+
lang_type: "ch"
251+
model_type: "mobile"
252+
ocr_version: "PP-OCRv4"
253+
254+
task_type: "rec"
255+
256+
model_path: null
257+
model_dir: null
258+
259+
rec_keys_path: null
260+
rec_img_shape: [3, 48, 320]
261+
rec_batch_num: 6
262+
```
263+
264+
`engine_type (str)`: 同Det部分介绍。
265+
266+
`lang_type (str)`: 支持检测的语种类型。这里指的是`LangRec`,具体支持的语种参见:[model_list](../../model_list.md).
267+
268+
`model_type (str)`: 同Det部分介绍。
269+
270+
`ocr_version (str)`: 同Det部分介绍。
271+
272+
`model_path (str)`: 文本识别模型路径,仅限于PaddleOCR训练文本识别模型。默认值为`None`。
273+
274+
`model_dir (str)`: 模型存放路径或目录。如果是PaddlePaddle,该参数则对应模型存在目录。其余推理引擎请使用`model_path`参数。
275+
276+
`rec_keys_path (str)`: 文本识别模型对应的字典文件,默认为`None`。
277+
278+
`rec_img_shape (List[int])`: 输入文本识别模型的图像Shape(CHW)。默认值为`[3, 48, 320]`。
279+
280+
`rec_batch_num (int)`: 批次推理的batch大小,一般采用默认值即可,太大并没有明显提速,效果还可能会差。默认值为6。

sconstruct

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ env.Append(
7272
symbolDictionaries=buildVars.symbolDictionaries,
7373
)
7474

75-
# Ensure parent directory exists
76-
env.Command("addon/globalPlugins", [], Mkdir("$TARGET"))
77-
7875
# Copy plugin source directory to target directory
7976
copyAddon = env.Command(PLUGIN_TARGET_DIR, PLUGIN_SOURCE_DIR, Copy("$TARGET", "$SOURCE"))
8077

@@ -86,8 +83,7 @@ installDependencies = env.Command(
8683
)
8784

8885
# Set proper dependencies between actions
89-
env.Requires(copyAddon, "addon/globalPlugins")
90-
env.Depends(installDependencies, copyAddon)
86+
env.Requires(installDependencies, PLUGIN_TARGET_DIR)
9187

9288

9389
if env["dev"]:

0 commit comments

Comments
 (0)