@@ -30,21 +30,65 @@ result.vis()
3030
3131输入支持传入YAML格式的配置文件,同时支持参数直接传入使用。
3232
33- === "传入 ` config.yaml ` 使用 "
33+ === "方法一:传入配置文件 "
3434
35- 1. 生成`default_rapidocr.yaml`的配置文件
35+ 1. 生成`default_rapidocr.yaml`的配置文件。终端执行以下代码,即可在当前目录下生成默认的`default_rapidocr.yaml`文件。
3636 ```bash linenums="1"
3737 $ rapidocr config
38+ # The config file has saved in ./default_rapidocr.yaml
3839 ```
39- 2. 根据自己的需要更改YAML相应的值
40- 3. 传入到`RapidOCR`中使用
40+ 2. 根据自己的需要更改YAML相应的值。例如使用openvino作为推理引擎,更改如下:
41+ ```yaml linenums="1"
42+ # 该配置文件命名为1.yaml
43+ Global:
44+ lang_det: "ch_mobile" # ch_server
45+ lang_rec: "ch_mobile"
46+ text_score: 0.5
47+
48+ use_det: true
49+ use_cls: true
50+ use_rec: true
51+
52+ min_height: 30
53+ width_height_ratio: 8
54+ max_side_len: 2000
55+ min_side_len: 30
56+
57+ return_word_box: false
58+
59+ with_onnx: false
60+ with_openvino: true # 更改这里为true
61+ with_paddle: false
62+ with_torch: false
63+
64+ font_path: null
65+ ... ...
66+ ```
67+ 3. 传入到`RapidOCR`中使用。
68+ ```python linenums="1"
69+ from rapidocr import RapidOCR
70+
71+ # 步骤2中的1.yaml
72+ config_path = "1.yaml"
73+ engine = RapidOCR(config_path=config_path)
74+
75+ img_url = "<https://img1.baidu.com/it/u=3619974146,1266987475&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=516>"
76+ result = engine(img_url)
77+ print(result)
78+
79+ result.vis()
80+ ```
81+
82+ === "方法二:直接传入相应参数"
83+
84+ 由于rapidocr中涉及可调节的参数众多,为了便于维护,引入[omageconf](https://github.com/omry/omegaconf)库来更新参数。这样带来的代价是传入参数没有1.x系列中直观一些。但是现阶段方式也容易理解和使用。
4185
42- === "直接传入参数"
86+ 例如,我想使用openvino作为推理引擎,可以通过下面这种方式使用:
4387
4488 ```python linenums="1"
4589 from rapidocr import RapidOCR
4690
47- engine = RapidOCR()
91+ engine = RapidOCR(params={"Global.with_openvino": True} )
4892
4993 img_url = "https://github.com/RapidAI/RapidOCR/blob/main/python/tests/test_files/ch_en_num.jpg?raw=true"
5094 result = engine(img_url)
@@ -53,10 +97,61 @@ result.vis()
5397 result.vis()
5498 ```
5599
100+ 其他参数传入方式,基本就是参考`config.yaml`,关键字之间用点分割,直接写就可以了。例如:
101+ ```python linenums="1"
102+ {
103+ "Global.with_openvino": True,
104+ "Global.use_det": True,
105+ "EngineConfig.torch.use_cuda", True, # 使用torch GPU版推理
106+ "EngineConfig.torch.gpu_id": 1, # 指定GPU id
107+ }
108+ ```
109+
56110#### 输出
57111
112+ RapidOCR输出包括4种类型:` Union[TextDetOutput, TextClsOutput, TextRecOutput, RapidOCROutput] ` 。这4种类型均是Dataclasses类,可以直接访问对应的键值。
113+
58114#### 选择不同推理引擎
59115
116+ ` rapidocr ` 支持4种推理引擎(ONNXRuntime / OpenVINO / PaddlePaddle / PyTorch),默认使用ONNXRuntime CPU版。
117+
118+ ` rapidocr ` 是通过指定不同参数来选择使用不同的推理引擎的。当然,使用不同推理引擎的前提是事先安装好对应的推理引擎库,并确保安装正确。
119+
120+ === "使用ONNXRuntime"
121+
122+ 在安装`rapidocr`时,已经自动安装好了,无需配置,可直接使用。
123+
124+ === "使用OpenVINO"
125+
126+ 1. 安装openvino
127+ ```bash linenums="1"
128+ pip install openvino
129+ ```
130+ 2. 指定openvino作为推理引擎
131+ ```python linenums="1"
132+ from rapidocr import RapidOCR
133+
134+ engine = RapidOCR(params={"Global.with_openvino": True})
135+
136+ img_url = "https://github.com/RapidAI/RapidOCR/blob/main/python/tests/ test_files/ch_en_num.jpg?raw=true"
137+ result = engine(img_url)
138+ print(result)
139+
140+ result.vis()
141+ ```
142+ 3. 查看输出日志。下面日志中打印出了**Using engine_name: openvino**,则证明使用的推理引擎是OpenVINO。
143+ ```bash linenums="1"
144+ [INFO] 2025-03-21 09:28:03,457 base.py:30: Using engine_name: openvino
145+ [INFO] 2025-03-21 09:28:03,553 utils.py:35: File already exists in /Users/joshuawang/projects/_self/RapidOCR/python/rapidocr/models/ch_PP-OCRv4_det_infer.onnx
146+ [INFO] 2025-03-21 09:28:03,767 base.py:30: Using engine_name: openvino
147+ [INFO] 2025-03-21 09:28:03,768 utils.py:35: File already exists in /Users/joshuawang/projects/_self/RapidOCR/python/rapidocr/models/ch_ppocr_mobile_v2.0_cls_infer.onnx
148+ [INFO] 2025-03-21 09:28:03,861 base.py:30: Using engine_name: openvino
149+ [INFO] 2025-03-21 09:28:03,862 utils.py:35: File already exists in /Users/joshuawang/projects/_self/RapidOCR/python/rapidocr/models/ch_PP-OCRv4_rec_infer.onnx
150+ ```
151+
152+ === "使用PaddlePaddle"
153+ === "使用PyTorch"
154+
60155#### 选择CPU / GPU
61156
62157#### 使用默认mobiel或server模型
0 commit comments