Skip to content

Commit 70795c9

Browse files
committed
指定字体文件的位置,方便离线部署
1 parent 97d9728 commit 70795c9

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

docs/version3.x/pipeline_usage/OCR.en.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,3 +1845,38 @@ from paddleocr import PaddleOCR
18451845

18461846
pipeline = PaddleOCR(paddlex_config="PaddleOCR.yaml")
18471847
```
1848+
1849+
#### 4.2.3 Specifying the Local Font File Path via Environment Variables
1850+
Before initializing the production line object, you can set an environment variable to specify the local font file path. This enables the production line to use the specified font when saving the annotated result image via the `save_to_img` method.
1851+
This approach is convenient for offline deployment as it eliminates the need to download font files over the network and simplifies file management. **It is essential to ensure that the specified font file exists!** **
1852+
1853+
Suppose the font file `simfang.ttf` is stored in the `fonts` folder in the current directory.
1854+
1855+
Python script:
1856+
1857+
```python
1858+
import os
1859+
1860+
# Specify the location of the font file before initializing the production line.
1861+
os.environ["PADDLE_PDX_LOCAL_FONT_FILE_PATH"] = "./fonts/simfang.ttf"
1862+
1863+
from paddleocr import PaddleOCR
1864+
1865+
ocr = PaddleOCR(
1866+
use_doc_orientation_classify=False,
1867+
use_doc_unwarping=False,
1868+
use_textline_orientation=False) # text detection + text recognition
1869+
# ocr = PaddleOCR(use_doc_orientation_classify=True, use_doc_unwarping=True) # text image preprocessing + text detection + textline orientation classification + text recognition
1870+
# ocr = PaddleOCR(use_doc_orientation_classify=False, use_doc_unwarping=False) # text detection + textline orientation classification + text recognition
1871+
# ocr = PaddleOCR(
1872+
# text_detection_model_name="PP-OCRv5_server_det",
1873+
# text_recognition_model_name="PP-OCRv5_server_rec",
1874+
# use_doc_orientation_classify=False,
1875+
# use_doc_unwarping=False,
1876+
# use_textline_orientation=False) # Switch to PP-OCRv5_server models
1877+
result = ocr.predict("./general_ocr_002.png")
1878+
for res in result:
1879+
res.print()
1880+
res.save_to_img("output")
1881+
res.save_to_json("output")
1882+
```

docs/version3.x/pipeline_usage/OCR.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,3 +1847,39 @@ from paddleocr import PaddleOCR
18471847

18481848
pipeline = PaddleOCR(paddlex_config="PaddleOCR.yaml")
18491849
```
1850+
1851+
#### 4.2.3 通过环境变量指定使用本地字体文件路径
1852+
在初始化产线对象前,可通过设置环境变量,指定本地字体文件路径,使产线在执行 save_to_img 方法保存标注结果图像时使用该字体。
1853+
方便离线部署时无需网络下载字体文件,便于文件的管理,**通过该方法需要确保指定的字体文件存在!**
1854+
1855+
示例如下:
1856+
假设字体文件 `simfang.ttf` 存放于当前目录下的 `fonts` 文件夹内
1857+
1858+
Python 脚本:
1859+
1860+
```python
1861+
import os
1862+
1863+
# 在初始化产线前指定字体文件的位置
1864+
os.environ["PADDLE_PDX_LOCAL_FONT_FILE_PATH"] = "./fonts/simfang.ttf"
1865+
1866+
from paddleocr import PaddleOCR
1867+
1868+
ocr = PaddleOCR(
1869+
use_doc_orientation_classify=False,
1870+
use_doc_unwarping=False,
1871+
use_textline_orientation=False) # 文本检测+文本识别
1872+
# ocr = PaddleOCR(use_doc_orientation_classify=True, use_doc_unwarping=True) # 文本图像预处理+文本检测+方向分类+文本识别
1873+
# ocr = PaddleOCR(use_doc_orientation_classify=False, use_doc_unwarping=False) # 文本检测+文本行方向分类+文本识别
1874+
# ocr = PaddleOCR(
1875+
# text_detection_model_name="PP-OCRv5_server_det",
1876+
# text_recognition_model_name="PP-OCRv5_server_rec",
1877+
# use_doc_orientation_classify=False,
1878+
# use_doc_unwarping=False,
1879+
# use_textline_orientation=False) # 更换 PP-OCRv5_server 模型
1880+
result = ocr.predict("./general_ocr_002.png")
1881+
for res in result:
1882+
res.print()
1883+
res.save_to_img("output")
1884+
res.save_to_json("output")
1885+
```

0 commit comments

Comments
 (0)